我试图在react本地应用程序中发出http请求,这会抛出一个错误
Uncaught Error: unsupported BodyInit type
at Response.Body._initBody (index.bundle?platform=android&dev=true&minify=false:13594)
at new Response (index.bundle?platform=android&dev=true&minify=false:13765)
at XMLHttpRequest.xhr.onload (index.bundle?platform=android&dev=true&minify=false:13820)在应用程序的index.js中,我添加了以下一行
GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest取取请求
const headers = {};
headers['Accept'] = 'application/json';
headers['Content-Type'] = 'application/json';
let response = await fetch('https://www.saramashkim.co.il/api/get_all_product', {
method: 'GET',
headers: headers,
body: null,
})当我在邮递员中检查这个网址时,它正常工作,我得到所有的数据..
发布于 2018-04-03 09:40:08
试试下面的代码:
var headers = {'Accept': 'application/json', 'Content-Type': 'application/json'};
fetch('https://www.saramashkim.co.il/api/get_all_product', {
method: 'GET',
headers: headers,
}).then((response) => response.json())
.then((responseJson) => {
console.log('response', responseJson);
})
.catch((error) =>{
console.error(error);
});您可以看到响应被记录到控制台。(我更新了我的答案)
repl:https://repl.it/@tejashwikalptar/samplefetchtest
截图:

https://stackoverflow.com/questions/49626431
复制相似问题