0
我有获取门票列表的API方法。当我在postman(Chrome扩展)中尝试这种方法时,一切正常。当我在原生反应中尝试相同时,它在授权方面存在一些问题 - 但在这两种情况下我都使用相同的标记。从Postman实现API查询到React Native
有邮差查询,它的工作原理正确的:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://example.com/api/tickets/list",
"method": "GET",
"headers": {
"authorization": "MzA4YTcwZjI2OGMMzNDhlZGVhYjUyNzQxNg==",
"cache-control": "no-cache",
"postman-token": "dc861781-6989-5707-d41f-ab52abda037d"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
并且存在与相同的数据,我想一个反应过来取本地方法,但工作不正常:
var url = 'https://example.com/api/tickets/list';
fetch(url, {
method: 'GET',
headers: {
'Authorization': 'MzA4YTcwZjI2OGMMzNDhlZGVhYjUyNzQxNg==',
'Cache-control': 'no-cache',
'Content-Type': 'application/json'
}
})
.then((response) => {
console.log(response);
return response.json();
})
.then((responseData) => {
var ticketList = responseData;
console.log(ticketList);
this.setState({
dataSource: this.state.dataSource
.cloneWithRows(ticketList)
});
})
.catch((error) => {
console.log(error);
});
怎么了?
你能提供错误字符串吗? – Mihir
401,未经授权。 – FladeX