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

后端 未结 6 1025
無奈伤痛
無奈伤痛 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:43

    To get rid of error:

    Type '"text"' is not assignable to type '"json"'.

    Use

    responseType: 'text' as 'json'

    import { HttpClient, HttpHeaders } from '@angular/common/http';
    .....
     return this.http
            .post(
                this.baseUrl + '/Tickets/getTicket',
                JSON.stringify(value),
            { headers, responseType: 'text' as 'json' }
            )
            .map(res => {
                return res;
            })
            .catch(this.handleError);
    

提交回复
热议问题