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.

Setting header: 'Content-Type': 'application/json' is not working

See original GitHub issue

Hi. I’m passing a custom header like this

axios.get('my/url', {
    headers: {
        'Content-Type': 'application/json'
    }
})

But it doesn’t seem to work. Any ideas?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:71
  • Comments:30 (1 by maintainers)

github_iconTop GitHub Comments

125reactions
dinodsauruscommented, May 16, 2018

Yep, I can confirm. If there is no data passed it removes the Content-Type… I just added data: {} to my GET request, and it works fine. It’s really weird to pass data on get requests but I don’t mind 👍

69reactions
adamrbennettcommented, Aug 29, 2018

If a user of this package wants to set a Content-Type header without a body, shouldn’t they be able to do that? I don’t see the argument for limiting the use here by either forcing a dummy payload or preventing the Content-Type header from being set. This choice should be up to the user unless there is a good reason to prevent it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP header('Content-Type: application/json'); is not working
For some reason, my response header always comes as Content-Type:text/html; charset=UTF-8. I want content type to be json (Content-Type: ...
Read more >
Working with application/json content type in Deno - Medium
Set content -type header to application/json. Here is an example of sending JSON in a fetch Request: const body={ a: 'b', c: 10...
Read more >
What is the Correct Content-Type for JSON? Request Header ...
This means when you're sending JSON to the server or receiving JSON from the server, you should always declare the Content-Type of the...
Read more >
How do I set the content type for a Curl request? - ReqBin
If you don't set the correct Content-Type, your app may not work. For example, the target server can accept XML and JSON data...
Read more >
The application/problem+json Content-Type - SymfonyCasts
Setting the Content-Type Header¶ ... When we try the tests, they still pass! And now the client knows a bit more about our...
Read more >

github_iconTop Related Medium Post

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