I have a method in an Ionic 3 (local) application consuming features of an external API, using the following method:
post(resource, body): Observable<any> {
return this.http
.post<Observable<any>>('${this.apiUrl}${resource}', JSON.stringify(body))
.map(response => response);
}
I'm getting error 401 (Unauthorized) in the response. The request header is as follows:
POST /v1/login HTTP/1.1
Host: xxxx.xxxx.xxxx.xxxx
Connection: keep-alive
Content-Length: 61
Accept: application/json, text/plain, */*
Origin: http://localhost:8100
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
Content-Type: text/plain
Referer: http://localhost:8100/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7
Already try to use headers = new HttpHeaders().set('Content-Type', 'application/json');
but the Content-Type continues being sent as text / plain and I need it to be application / json.
Any way to resolve this?
Note 1: The CORS issue that typically occurs in these requests has been resolved with a Google Chrome plugin.
Note 2: When this same request is made by Postman, everything happens as it should, returning everything right.