angular ionic http 请求将空数据发送到 rest API
angular ionic http request sends null data to rest API
我正在尝试将数据从 angular 表单发送到端点。
此 angular 表单位于 ionic 4 应用程序中。但我得到的只是后端的空数据。但是当我对邮递员进行同样的尝试时,它起作用 fine.I 也尝试将内容类型更改为 "application/json" 但它也给出了相同的结果。对于后端,我使用 php api。
// Http Options,where I set http headers
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data;boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
};
// Create a new user
createUser(user: User): Observable<User> {
return this.http
.post<User>(this.url + 'test/create' , user , this.httpOptions)
.pipe(
retry(0),
// handle error method is already implemented above
catchError(this.handleError)
);
}
}
I'm not receiving any errors in chrome console.
您需要将数据作为表单数据传递如下:
const newUser = new FormData();
newUser.append('firstName', user.firstName);
然后在您的 post 中传递 newUser。
我正在尝试将数据从 angular 表单发送到端点。 此 angular 表单位于 ionic 4 应用程序中。但我得到的只是后端的空数据。但是当我对邮递员进行同样的尝试时,它起作用 fine.I 也尝试将内容类型更改为 "application/json" 但它也给出了相同的结果。对于后端,我使用 php api。
// Http Options,where I set http headers
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data;boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
};
// Create a new user
createUser(user: User): Observable<User> {
return this.http
.post<User>(this.url + 'test/create' , user , this.httpOptions)
.pipe(
retry(0),
// handle error method is already implemented above
catchError(this.handleError)
);
}
}
I'm not receiving any errors in chrome console.
您需要将数据作为表单数据传递如下:
const newUser = new FormData();
newUser.append('firstName', user.firstName);
然后在您的 post 中传递 newUser。