API returns 邮递员 200 但设备 404
API returns 200 in postman but 404 in device
我使用 koa 服务器和 postgresql 数据库为我的应用程序创建了一个简单的 api,并使用 postman 和浏览器对其进行了测试,两者都运行良好。现在我正在尝试在我的本机反应应用程序中获取数据(在实际设备上测试)但它返回给我这个响应:
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "1bbc1ba3-a1b4-442e-ba85-d09d5d54f4e6", "offset": 0, "size": 9}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "1bbc1ba3-a1b4-442e-ba85-d09d5d54f4e6", "offset": 0, "size": 9}}, "headers": {"map": {"content-length": "9", "content-type": "text/plain; charset=utf-8", "date":
"Mon, 20 Apr 2020 12:26:12 GMT"}}, "ok": false, "status": 404, "statusText": undefined, "type": "default", "url":
"https://a1cd97c8.ngrok.io/posts/,function%20dispatchAction()%20%7B%20%20%20%20[native%20code]%7D"}
我正在使用 ngrok URL 映射,因为没有 https,我的请求会直接被拒绝。
这是我的请求代码:
const searchURL = React.useState('https://a1cd97c8.ngrok.io/posts/');
const fetchPosts = async () => {
console.log('fetching');
fetch(searchURL, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => {
console.log('response: ', response);
return response.json();
})
.then((json) => console.log('TESTOUTPUT', json))
.catch((err) => console.log('error: ', err.message));
};
我在 catch 块中得到的错误消息是:
error: JSON Parse error: Unexpected identifier "Not"
我做错了什么?
useState
hook return 一个数组所以你应该解构结果
const [searchURL, setSearchURL] = React.useState('https://a1cd97c8.ngrok.io/posts/');
我使用 koa 服务器和 postgresql 数据库为我的应用程序创建了一个简单的 api,并使用 postman 和浏览器对其进行了测试,两者都运行良好。现在我正在尝试在我的本机反应应用程序中获取数据(在实际设备上测试)但它返回给我这个响应:
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "1bbc1ba3-a1b4-442e-ba85-d09d5d54f4e6", "offset": 0, "size": 9}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "1bbc1ba3-a1b4-442e-ba85-d09d5d54f4e6", "offset": 0, "size": 9}}, "headers": {"map": {"content-length": "9", "content-type": "text/plain; charset=utf-8", "date":
"Mon, 20 Apr 2020 12:26:12 GMT"}}, "ok": false, "status": 404, "statusText": undefined, "type": "default", "url":
"https://a1cd97c8.ngrok.io/posts/,function%20dispatchAction()%20%7B%20%20%20%20[native%20code]%7D"}
我正在使用 ngrok URL 映射,因为没有 https,我的请求会直接被拒绝。
这是我的请求代码:
const searchURL = React.useState('https://a1cd97c8.ngrok.io/posts/');
const fetchPosts = async () => {
console.log('fetching');
fetch(searchURL, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => {
console.log('response: ', response);
return response.json();
})
.then((json) => console.log('TESTOUTPUT', json))
.catch((err) => console.log('error: ', err.message));
};
我在 catch 块中得到的错误消息是:
error: JSON Parse error: Unexpected identifier "Not"
我做错了什么?
useState
hook return 一个数组所以你应该解构结果
const [searchURL, setSearchURL] = React.useState('https://a1cd97c8.ngrok.io/posts/');