0

I would like to send a POST-request using the Angular 5 HttpClient. My code looks like:

async download(body: PostZipFileRequest): Promise<any> {
    const post: string = environment.zipFileDownload;
    const httpHeaders = new HttpHeaders({
      'Content-Type': 'application/json',
      'Accept': 'application/json'
  });
    try {
        return await this.http.post(post, body.Assets, {
            headers: httpHeaders
        }).toPromise();
    } catch (error) {
        this.handleError(error);
    }
}

But I get an error of type: Status Code:415 Unsupported Media Type

enter image description here

because the Content-Type is 'text/plain' and not 'application/json'. Why isn't it json like I would expect? My WebAPI only accepts JSON. If I do a GET-request I don't need any headers. Angular sends "application/json" as Content-Type by default.

Rocco Hundertmark
  • 545
  • 2
  • 7
  • 20

0 Answers0