无法使用 axios 使用 headers 发送获取请求
Unable to send get request with headers using axios
能够在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 删除。检查下面问题的答案。
能够在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 删除。检查下面问题的答案。