question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can i change the headers['content-type'] before a get request?

See original GitHub issue

our back api limit the request content-type must be an fixed value, even it’s a get request.

but i see the source code will remove the content-type when request data is undefined,

so i set an empty data before request, like

if (!config.data) { config.data = "" } then set the content-type . this will work well on IOS device; but crashed on android device,

it will throw an error,

GET must not have a request body

is there any solution to fix this problem? thanks~

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
anthonygauthiercommented, Jul 17, 2018

Hi @HengCC,

I believe what you’re looking for is something like this:

axios.get('some_url', {headers: {Content-Type: 'application/json'}})
  .then((res) => {
    //do something
  })
  .catch((err) => {
    //do something
  });

Cheers 😄,

1reaction
mrgurdeepcommented, Nov 16, 2018

@delirius325 It does not gets sent as the header gets deleted here https://github.com/axios/axios/blob/98080381fa78dcffa91a15e6d25617583d13e533/dist/axios.js#L802

and if you would debug at this line before and after you would see this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content-Type - HTTP - MDN Web Docs - Mozilla
In responses, a Content-Type header provides the client with the actual content type of the returned content. This header's value may be ignored ......
Read more >
Do I need a content-type header for HTTP GET requests?
GET requests can have "Accept" headers, which say which types of content the client understands. The server can then use that to decide ......
Read more >
Content-Type Header Automatically Added to GET Requests
Click on any GET request to load it into the editor. Notice that there will be a Content-Type set in the Headers section....
Read more >
HTTP/1.1: Header Field Definitions
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used...
Read more >
Quickstart — Requests 2.28.1 documentation
Content-Length headers will be overridden when we can determine the length of the content. Furthermore, Requests does not change its behavior at all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found