[英]Unable to send get request with headers using axios
Able to get the response in postman
. 能够得到
postman
的回应。 But unable to get in axios
. 但是无法进入
axios
。 Getting html as response. 获取html作为响应。 What would be the problem?
有什么问题吗?
import axios from 'react-native-axios';
var config = {
headers: {
'Content-Type': 'Application/Json',
'JsonStub-User-Key': '__USER__KEY',
'JsonStub-Project-Key': '__PROJECT__KEY'
}
};
export async function menuListByCategories() {
// simulate an asynchronous operation
const url = "http://jsonstub.com/burgers";
axios.get(url, {config})
.then((response) = > {
console.log(response.data);
})
.
catch ((error) = > {
console.log("axios error:", error);
});
}
Update: check the response of this code 更新: 检查此代码的响应
You can add data: {}
in config
in order not to have Content-Type
removed by axios. 您可以在
config
中添加data: {}
,以免axios删除Content-Type
。 Check the answer of the question below. 检查以下问题的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.