能够在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);
});
}
答案 0 :(得分:1)
您可以在data: {}
中添加config
,以免被axios删除Content-Type
。检查下面问题的答案。