Angular Ionic HTTP请求将空数据发送到其余API

问题描述 投票:0回答:1

我正在尝试从角度形式向端点发送数据。此角形式为ionic 4应用程序。但是我得到的只是后端的空数据。但是,当我对邮递员尝试相同的方法时,效果很好。我也尝试将内容类型更改为“ 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.
angular ionic4
1个回答
0
投票

您需要按以下方式将数据作为表单数据传递:

const newUser = new FormData(); 
newUser.append('firstName', user.firstName);

然后在您的帖子中传递newUser。

© www.soinside.com 2019 - 2024. All rights reserved.