我无法通过Axios发出成功的请求。我已经与Postman进行了测试,以确保服务器正确无误,并且可以正常工作。
我得到的错误是
Network Error
- node_modules/axios/lib/core/createError.js:15:17 in createError
- node_modules/axios/lib/adapters/xhr.js:80:22 in handleError
- node_modules/event-target-shim/dist/event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:574:29 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue
我拨打后端电话的方式是
const onSubmit = (e) => {
axios.get(`https://127.0.0.1:8080/tasks/`).then((res) => {}).catch((e) => console.log(e));
};
我在轴距方面做错了吗?由于我的print("hit")
从未通过电话登录(虽然与邮递员合作),所以我什至没有碰到端点。
感谢您的帮助
使用提取时
const onSubmit = () => {
const requestOptions = {
method: 'POST',
headers: { Content_Type: 'application/json' },
body: JSON.stringify({ id, title, description, date: moment.utc(date).format('YYYY-MM-DD') })
};
fetch(`http://10.0.0.150:8080/tasks/update_task`, requestOptions)
.then((res) => {
return res.json();
})
.then((data) => {
console.log('the task is: ', task);
console.log('succeeded');
})
.catch((e) => console.log(e));
};