react-native fetch - request body - Unexpected EOF

前端 未结 2 396
醉话见心
醉话见心 2021-01-27 07:22

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,

相关标签:
2条回答
  • 2021-01-27 07:48

    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();

    0 讨论(0)
  • 2021-01-27 07:55
    var Url = "https://----------";
        return fetch(Url, {
            method: "POST",
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({'number': '11111111-'})
        })
            .then((response) => response.text())
            .then((responseJson) => {
                 const resposeJson2 = responseJson.length ? JSON.parse(responseJson) : {};
                console.log("SEND_SMS RESULT: ",responseJson2);
            })
            .done();
    

    Your server is returning null instead of error and unfortunately response.json() cant operate on null response you can research briefly on it the keywords are "Handling null response from api"

    0 讨论(0)
提交回复
热议问题