Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header keys become lowercase when interacting with API - React native

When interacting with API, the custom Header key always become lowercase. I'm use Fetch, Axios, XMLHttpRequest and Frisbee (javascript network library) but the key always lowercase

My snippet code like this (with fetch() method), The key I'm push is: 'Token-Api' but the server receive: 'token-api', so it's show the error 401. It's work with Postman:

 const request = 'https://abcxyz';
 fetch(request, {
   method: 'GET',
   headers: {
     'Content-Type': 'application/json',
     'Token-Api':'...abcxyz....'
   }
 }).then((response) => {
            log(abcxyz)
        })...

What do I need to do?

like image 508
3 revs Avatar asked Sep 13 '17 14:09

3 revs


People also ask

Can HTTP headers be lowercase?

All HTTP header keys are converted to lowercase in both directions (since HTTP header keys are defined to be case-insensitive). You should use lowercase in all of your mapping and classification rules.

Does Axios lowercase headers?

Per the specification, header names are case sensitive.

Is Accept header case sensitive?

It's case insensitive, but if you're going to fix the case, it should be 'Content-Type'.


1 Answers

you can read this post: Are HTTP headers case-sensitive?

According to RFC 2616, HTTP headers should be case-insensitive. So this is not the bug of the libraries you mention above. You should fix the server to treat Token-Api and token-api at the same way.

like image 88
Harlan Avatar answered Oct 10 '22 05:10

Harlan