React Native Post Request via Fetch throws Network Request Failed

前端 未结 9 1587
[愿得一人]
[愿得一人] 2020-12-15 16:51

I´ve came across the following error. At the moment I developing an Android App with React Native therefore I´m planning to use fetch for doing a post request for me.

9条回答
  •  难免孤独
    2020-12-15 17:11

    None of above answers were helped me. the problem was headers:

    Old header:

    fetch(API_HOST, {
                    method: 'POST',
                    headers: {
                        Accept: 'application/json'
                    },
                    body: JSON.stringify(data),
    

    Updated header:

    fetch(config.API_HOST, {
                    method: 'POST',
                    headers: {
                        Accept: 'application/json',
                        'Content-Type': 'application/json'  // I added this line
                    },
                    body: JSON.stringify(data),
    

提交回复
热议问题