简体   繁体   中英

Custom HTTP headers in Fetch API react native

An API I am trying to call need some custom headers like this

'aa11': 'value1'
'bb22': 'value2'

In postman, I call like this and it is working. 在此处输入图像描述

I need to call that API from my react native app so I searched at internet how to add custom headers in fetch and I tried like this.

fetch('www.api.com', {headers: {'aa11': 'value1', 'bb22': 'vaule2'}}).then(res => res.json()).then(result => console.log(result))

But it is not working. What am I missing here?

After struggling for a few days, I found out the answer. I need to add this in headers.

'Accept-Encoding': 'gzip, deflate, br'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM