react-native fetch - request body - Unexpected EOF

二次信任 提交于 2020-01-30 11:18:07

问题


in my react-native application, I'm trying to make fetch request with body. But, I get error message of unexpected EOF. Actually, the request is made, I mean I can see through backend logs that request is sent, whereas, right after the request, it shows error message.

Here is my fetch method.

var Url = "https://----------";
        return fetch(Url, {
            method: "POST",
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({'number': '11111111-'})
        })
            .then((response) => response.json())
            .then((responseJson) => {
                console.log("SEND_SMS RESULT: ",responseJson);
            })
            .done();

here is the error screen I get.


回答1:


I would say that it fails on this line: response.json() Are you sure that your response is a valid JSON?

Try testing the response with Postman or add .catch(e => console.log(e)) before done();



来源:https://stackoverflow.com/questions/46727831/react-native-fetch-request-body-unexpected-eof

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!