与API交互时,标头键变为小写-React native [英] Header keys become lowercase when interacting with API - React native

查看:92
本文介绍了与API交互时,标头键变为小写-React native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与API交互时,自定义标头密钥始终变为小写.我使用的是FetchAxiosXMLHttpRequestFrisbee(JavaScript网络库),但是键始终是小写

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

我的片段代码是这样的(使用fetch()方法),我按下的键是:'Token-Api',但是服务器收到:'token-api',因此显示错误401.它适用于Postman:

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)
        })...

我需要做什么?

推荐答案

您可以阅读以下文章: HTTP标头是否区分大小写?

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

根据RFC 2616,HTTP标头应不区分大小写.因此,这不是您上面提到的库的错误.您应该修复服务器,以相同的方式对待Token-Apitoken-api.

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.

这篇关于与API交互时,标头键变为小写-React native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆