最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Header keys become lowercase when interacting with API - React native - Stack Overflow

programmeradmin4浏览0评论

When interacting with API, the custom Header key always bee 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?

When interacting with API, the custom Header key always bee 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?

Share Improve this question asked Sep 13, 2017 at 14:55 bkit4ubkit4u 5352 gold badges5 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14

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.

You can actually solve this quite easily with another header:

sensitive: true

发布评论

评论列表(0)

  1. 暂无评论