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