Javascript 为什么我';我在尝试使用axios发送post请求时遇到网络错误
我在尝试使用axios发送post请求时遇到网络错误 错误: 网络错误 在createError中的节点\u modules\axios\lib\core\createError.js:15:17处 在handleError中的节点\u modules\axios\lib\adapters\xhr.js:81:22处 在EventTarget.prototype.dispatchEvent中的节点\u modules\event target shim\dist\event target shim.js:818:20处 在setReadyState中的节点_modules\react native\Libraries\Network\XMLHttpRequest.js:600:10处 在节点\u modules\react native\Libraries\Network\XMLHttpRequest.js:395:6 in\uu didCompleteResponse 在emit中的节点\u modules\react native\Libraries\vendor\emitter\EventEmitter.js:189:10 在节点\u modules\react native\Libraries\BatchedBridge\MessageQueue.js:416:4的调用函数中 在节点\u modules\react native\Libraries\BatchedBridge\MessageQueue.js:109:6 in\uuuuu-guard$argument\u 0 在\uuuGuard中的节点\u modules\react native\Libraries\BatchedBridge\MessageQueue.js:364:10 在callFunctionReturnFlushedQueue中的节点_modules\react native\Libraries\BatchedBridge\MessageQueue.js:108:4处 在[本机代码]:callFunctionReturnFlushedQueue中为null 代码: 当直接使用axios.post()时,一切正常,但是在我尝试导入一个函数后,它应该做完全相同的事情,我得到了这个网络错误 具有上述功能的库:Javascript 为什么我';我在尝试使用axios发送post请求时遇到网络错误,javascript,react-native,express,axios,Javascript,React Native,Express,Axios,我在尝试使用axios发送post请求时遇到网络错误 错误: 网络错误 在createError中的节点\u modules\axios\lib\core\createError.js:15:17处 在handleError中的节点\u modules\axios\lib\adapters\xhr.js:81:22处 在EventTarget.prototype.dispatchEvent中的节点\u modules\event target shim\dist\event target shi
const {Creq_testowy} = require("./Creq_testowy");
module.exports={
testowy: Creq_testowy,
}
功能本身:
const axios = require("axios");
function Creq_testowy() {
return new Promise((resolve, reject) => {
axios.post(`http://192.168.0.4:8080/testowy`)
.then(res => {
console.log(res.data);
resolve(res.data);
})
.catch(error => {console.log(error)})
});
}
module.exports = {
Creq_testowy,
}
为什么直接使用axios.post()时一切正常?
为什么在使用导入的函数时会出现此错误?为什么要在axios已返回承诺时创建承诺? 你能试试这个吗
async function Creq_testowy() {
const res = await axios.post(`http://192.168.0.4:8080/testowy`)
return res.data;
}
还是这个
async function Creq_testowy() {
try {
const res = await axios.post(`http://192.168.0.4:8080/testowy`)
return res.data;
} catch(err) {
console.log(err);
}
}
您是否在RET native中运行此代码?博览会?网络
您是否也传递为brevety隐藏的post参数?
这可能是错误的根本原因。为什么要在axios已经返回承诺的情况下创建承诺? 你能试试这个吗
async function Creq_testowy() {
const res = await axios.post(`http://192.168.0.4:8080/testowy`)
return res.data;
}
还是这个
async function Creq_testowy() {
try {
const res = await axios.post(`http://192.168.0.4:8080/testowy`)
return res.data;
} catch(err) {
console.log(err);
}
}
您是否在RET native中运行此代码?博览会?网络
您是否也传递为brevety隐藏的post参数?
这可能是错误的根本原因。能否尝试用以下代码替换代码:
const axios = require("axios");
async function Creq_testowy() {
const data = await axios.post(`http://192.168.0.4:8080/testowy`)
return data.data
}
module.exports = {
Creq_testowy,
}
您是否可以尝试用以下代码替换代码:
const axios = require("axios");
async function Creq_testowy() {
const data = await axios.post(`http://192.168.0.4:8080/testowy`)
return data.data
}
module.exports = {
Creq_testowy,
}
它现在可以工作了,但是为什么我以前的版本会产生这个错误呢?谢谢你:过了一段时间,我又回到了这个话题,我以前的想法也很有效,所以很奇怪。我重新启动了Android Studio,现在可以正常工作了。现在可以工作了,但是为什么我以前的版本会产生这个错误呢?谢谢你:过了一段时间,我又回到了这个话题,我以前的想法也很有效,所以很奇怪。我重新启动了Android Studio,现在可以正常工作了。现在可以工作了,但我不知道为什么我的上一个程序会产生网络错误。谢谢,它是react native,我正在使用expo、android studio和android emulator。另外:过了一段时间,我又回到了这个,我以前的soultion也能工作,所以很奇怪。我重新启动了Android Studio,现在可以正常工作了。现在可以工作了,但我不知道为什么我的上一个程序会产生网络错误。谢谢,它是react native,我正在使用expo、android studio和android emulator。另外:过了一段时间,我又回到了这个,我以前的soultion也能工作,所以很奇怪。我重新启动了Android Studio,现在它工作正常。