当我使用他们网站上描述的Fetch API时,这是我得到的错误:
TypeError: Network request failed
at xhr.onload (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:5881:8)
at XMLHttpRequest._sendLoad (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:19897:1)
at XMLHttpRequest.setReadyState (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:19887:6)
at XMLHttpRequest._didCompleteResponse (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:19782:6)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:19736:105
at EventEmitter.emit (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:18050:23)
at MessageQueue.__callFunction (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:16698:23)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:16602:8
at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:16556:1)
at MessageQueue.callFunctionReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false:16601:1)
以下是触发此错误的代码:
fetch(`${baseUrl}/basecomponents.js`)
.then(myFunction)
.catch(errorHandler);
我搜索了解决方案,并发现很少的主题说gzip压缩on react native在使用Fetch API时崩溃应用程序,所以我尝试了,没有任何反应。同样的错误。
然后我尝试了XMLHttpRequest API。这是代码:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4/* && xhttp.status == 200*/) {
console.log(xhttp.responseText);
}
};
xhttp.open("GET", `${baseUrl}/basecomponents.js`, true);
xhttp.send();
这也不行。我收到"Unable to resolve host http://arbormis.loc"
错误。所以我无法在Android上发出任何网络请求。请帮忙!