Angular 4/5 HttpClient: Argument of type string is not assignable to 'body'

前端 未结 4 1470
醉酒成梦
醉酒成梦 2020-11-30 05:58

The Angular docs say:

The response body doesn\'t return all the data you may need. Sometimes servers return special headers or status codes to indic

4条回答
  •  醉话见心
    2020-11-30 06:18

    Typescript complains about this problem

    Type 'string' is not assignable to type "body"

    To solve this, convert string to body manually. Example:

        const httpOptions = {
          headers: new HttpHeaders({
            'Content-Type': 'application/json'
          }),
          observe: 'response' as 'body'
        };
        return this.http.post(url, data, httpOptions);
    

提交回复
热议问题