Angular 6: How to set response type as text while making http call

后端 未结 6 1026
無奈伤痛
無奈伤痛 2020-11-28 09:05

I trying to make http request to the spring rest API.. API returns a string value (\"success\" or \"fail\")... but I dont know how to set the response type as string value w

6条回答
  •  春和景丽
    2020-11-28 09:33

    Have you tried not setting the responseType and just type casting the response?

    This is what worked for me:

    /**
     * Client for consuming recordings HTTP API endpoint.
     */
    @Injectable({
      providedIn: 'root'
    })
    export class DownloadUrlClientService {
      private _log = Log.create('DownloadUrlClientService');
    
    
      constructor(
        private _http: HttpClient,
      ) {}
    
      private async _getUrl(url: string): Promise {
        const httpOptions = {headers: new HttpHeaders({'auth': 'false'})};
        // const httpOptions = {headers: new HttpHeaders({'auth': 'false'}), responseType: 'text'};
        const res = await (this._http.get(url, httpOptions) as Observable).toPromise();
        // const res = await (this._http.get(url, httpOptions)).toPromise();
        return res;
      }
    }
    

提交回复
热议问题