反应原生提取http请求抛出错误

时间:2018-04-03 09:20:05

标签: http react-native fetch

我试图在本机应用程序中发出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中检查这个网址时,它工作正常,我得到了所有数据..

1 个答案:

答案 0 :(得分:1)

尝试以下代码:

mkdir -p /home/gitlab-runner/cache/web/app/app/

sudo chown -R gitlab-runner:gitlab-runner /home/gitlab-runner/cache/

您可以看到响应已记录到控制台。 (我已经更新了我的答案)

repl:https://repl.it/@tejashwikalptar/samplefetchtest

截图: REPL Screenshot with API result