angular2-jwt icon indicating copy to clipboard operation
angular2-jwt copied to clipboard

0.1.17 per-request header configuration doesn't work

Open vicrep opened this issue 10 years ago • 7 comments

Assuming the default configuration (AUTH_HTTP_PROVIDERS)

const BASE_REQ_OPTS = new RequestOptions({
  headers: new Headers({ 'Content-Type': 'application/json' })
});

this.authHttp.post(
      ENDPOINT,
      JSON.stringify(<Your Object>),
      BASE_REQ_OPTS
    ).map(res => res.json())

this will cause the post to be sent with a content-type of 'text/plain' (I believe the default http request type), whatever options you pass during the request.

0.1.16 functions as expected

vicrep avatar Jul 18 '16 22:07 vicrep

We've encountered a similar problem since upgrading from version 0.1.16 to 0.1.1.17. We create a HTTP POST request and set the Content-Type to application/json, however when the request is executed we can see the Content-Type is text/plain. Rolling back to 0.1.16 for now.

CrisGrec avatar Jul 19 '16 09:07 CrisGrec

Experiencing the same thing. I rolled back to 0.1.15

scttcper avatar Jul 20 '16 17:07 scttcper

Although I’ve update this module to 0.1.18, I have the same problem still. It seems to ignore header configuration.

lazyhoneyant avatar Jul 21 '16 19:07 lazyhoneyant

@lazyhoneyant can you show how you're configuring your headers?

chenkie avatar Jul 21 '16 21:07 chenkie

Below code is used in ionic2 framework. Previous version of angular2-jwt is working well. But after upgrade to latest version, It doesn't work as i said. No matter what I do, Content-type in Request header is 'text/plain'. thanks.

let apiUrl = 'http://';
let headers = new Headers({ 'Content-Type':'application/json'});
let options = new RequestOptions({headers:headers});

return this.authHttp.put(apiUrl, JSON.stringify({data:'test'}), options)      
            .map(this.extractData)
            .catch(this.handleError);

lazyhoneyant avatar Jul 22 '16 07:07 lazyhoneyant

Instead of providing a RequestOptions, can you try providing your headers object directly?

let apiUrl = 'http://';
let headers = new Headers({ 'Content-Type':'application/json'});

return this.authHttp.put(apiUrl, JSON.stringify({data:'test'}), { headers })      
            .map(this.extractData)
            .catch(this.handleError);

chenkie avatar Jul 22 '16 14:07 chenkie

Thanks for answering. I’ve checked and installed all of things again. Then It works well now.

lazyhoneyant avatar Jul 22 '16 15:07 lazyhoneyant