我无法使用 post 方法使其处理 fetch 请求,而 get 其他 api 调用效果很好。这是我的代码:
return fetch(URL_LOCAL + `/addLike`, {
method: 'post',
body: JSON.stringify({a: 1})
})
.then(response => Promise.all([response, response.json()]))
.catch(err => {
return Promise.reject(err);
})
我在获取 URL_LOCAL 之前创建了一个 console.log 并且它返回http://localhost:5000很好。
它给了我这个错误:
Network request failed
at XMLHttpRequest.xhr.onerror (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:15825)
at XMLHttpRequest.dispatchEvent (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:17902)
at XMLHttpRequest.setReadyState (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:17657)
at XMLHttpRequest.__didCompleteResponse (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:17484)
at blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:17594
at RCTDeviceEventEmitter.emit (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:3480)
at MessageQueue.__callFunction (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:2386)
at blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:2156
at MessageQueue.__guardSafe (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:2348)
at MessageQueue.callFunctionReturnFlushedQueue (blob:http://localhost:8081/459df9ca-c7b8-48bc-9c45-03d2f1e94f1d:2155)
我在使用 chrome 开发工具查看日志的 android 模拟器上,我使用 node 和 mongodb 作为后端,但我在调用的开头放置了一个日志但没有被触发
编辑:我让它工作,但生产中的 api 与我在 localhost:5000 中使用的代码相同,我不知道 localhost 有什么问题