反应本机获取http请求抛出错误

反应本机获取http请求抛出错误,http,react-native,fetch,Http,React Native,Fetch,我试图在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

我试图在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,
        })
当我在POSTMAN中检查此url时,它工作正常,我获得了所有数据。

请尝试以下代码:

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);
  });
您可以看到响应被记录到控制台。我已经更新了我的答案

答复:

截图:

不确定,“GET”方法没有任何正文。。所以这不是问题,删除bodyCORS是不允许在你的URL端的,所以我无法测试它,但在我的本地服务器上,这在我的本地服务器上运行良好,它也运行良好。但我希望它能在react原生应用程序中工作。。