Tuesday, June 26, 2018

Error : Argument of type '{ headers: HttpHeaders; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | .......

If You have this error in angular request for response type "text",


Argument of type '{ headers: HttpHeaders; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "bod
y"; params?: Ht...'.


You need to set header from .... 


    let headers = new HttpHeaders({
        'Content-Type': 'application/json',
        'Authorization': window.sessionStorage.token
      });
      let authHttpOptions = {
       headers : headers,
        responseType: 'text'
      }


       this.http.post(url, param, authHttpOptions)
          .subscribe(..)



to 
 this.http.post(url, param, {
          headers: new HttpHeaders({'Content-Type': 'application/json', 'Authorization': window.sessionStorage.token}),
          responseType : 'text'
 })
          .subscribe( ...) 

No comments:

Post a Comment