能够在postman
中获取响应。但无法进入axios
。获取 html 作为响应。会有什么问题呢?
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);
});
}
最佳答案
您可以在config
中添加data: {}
,以免Content-Type
被axios删除。检查以下问题的答案。
关于javascript - 无法使用 axios 发送带 header 的 get 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47120899/