小编Sly*_*tis的帖子

Angular 2 http post params and body

我正试图通过我的角度应用程序进行api调用.我想要做的是使用命令参数向api发送一个post请求.我已经做了很多服务器端测试以及完成传出请求,$_POST而且body数据永远不存在.因此,我很确定这个问题存在于这段代码中.

public post(cmd: string, data: object): Observable<any> {

    const params = new URLSearchParams();
    params.set('cmd', cmd);

    const options = new RequestOptions({
      headers: this.getAuthorizedHeaders(),
      responseType: ResponseContentType.Json,
      params: params,
      body: data,
      withCredentials: false
    });

    console.log('Options: ' + JSON.stringify(options));

    return this.http.post('http://t2w.dev/index.php', data, options)
      .map(this.handleData)
      .catch(this.handleError);
  }
Run Code Online (Sandbox Code Playgroud)

我尝试了许多不同的JSON结构,data但这是我尝试发送的核心:

{
  "Username": "No thanks",
  "Password": "Donno"
}
Run Code Online (Sandbox Code Playgroud)

this.handleData并且this.handleError是一种将数据和错误作为参数的方法,并返回我想要的内容.

api设置为记录任何通过$_POST哪些工作正常运行请求从任何地方,但我的角度应用程序.到目前为止我做了什么:

  1. 传递原始查询而不是URLSearchParams.
  2. 没有身体传递请求.
  3. 传递RequestOptions中的所有值.
  4. 将params作为字符串传递.
  5. 传递身体作为params.
  6. 传递身体为JSON.stringify({"用户名":"不,谢谢","密码":"唐诺"}

控制台输出 RequestOptions

选项:{"method":null,"headers":{"Content-Type":["application/json"],"Accept":["application/json"],"X-CLIENT-ID":[" 380954038 "]," X-CLIENT-SECRET ":[" 5BgqRO9BMZ4iocAXYjjnCjnO7fHGN59WP8BTRZ5f "]},"身体":"{}", …

angular-http angular

12
推荐指数
2
解决办法
8万
查看次数

BottomSheetDialogFragment AdjustResize SoftInput 不起作用

嘿,我目前正在尝试创建一个具有以下布局的 BottomSheetDialogFragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    android:layout_alignParentBottom="true">
    <com.indico.recorder.views.DonkeyConstraintLayout
        android:id="@+id/album_edit_info_container"
        android:layout_width="match_parent"
        android:backgroundTint="@color/colorBackgroundTinted"
        android:layout_height="wrap_content"
        android:clipChildren="true"
        android:clipToPadding="true">
        <View
            android:id="@+id/album_edit_draggable_indicator"
            android:layout_width="40dp"
            android:layout_height="4dp"
            android:alpha="0.65"
            android:background="@drawable/draggable_indicator"
            app:layout_constraintBottom_toTopOf="@id/album_edit_title_container"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="16dp"
            android:elevation="1dp"/>
        <android.support.design.widget.TextInputLayout
            android:id="@+id/album_edit_title_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintTop_toBottomOf="@id/album_edit_draggable_indicator"
            app:layout_constraintBottom_toTopOf="@id/album_edit_description_container"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">
            <com.indico.recorder.views.AutoClearEditText
                android:id="@+id/album_edit_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:maxLength="@integer/media_title_max_length"
                android:hint="@string/session_name_hint"
                android:imeOptions="actionNext"/>
        </android.support.design.widget.TextInputLayout>
        <android.support.design.widget.TextInputLayout
            android:id="@+id/album_edit_description_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintBottom_toTopOf="@id/albumEditDivider"
            app:layout_constraintTop_toBottomOf="@id/album_edit_title_container"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">
            <android.support.design.widget.TextInputEditText
                android:id="@+id/album_edit_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="75dp"
                android:textAlignment="textStart"
                android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
                android:maxLines="@integer/media_description_max_length"
                android:hint="@string/session_description_hint"
                android:gravity="start|top"
                android:visibility="visible"/>
        </android.support.design.widget.TextInputLayout>
        <View
            android:id="@+id/albumEditDivider"
            android:layout_width="match_parent"
            android:layout_height="0.2dp"
            android:alpha="0.75" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-softkeyboard android-fragments bottom-sheet

7
推荐指数
1
解决办法
1605
查看次数