Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fetch returning empty response

I am using fetch on expternal API and seem to be receiving empty response (Not empty body but fully empty resonse)

 

const data = {'id': 'id'};
        
        var options = { 
          method: 'POST',
          body: JSON.stringify(data),
          json: true,
          headers: { 
            'cache-control': 'no-cache',
            'Content-Type': 'application/json'
          },
        };
        
        fetch(url, options)
            .then(function (response) {
                console.log(response);
            })
            .catch(function (err) {
            console.log("Error : " + err);
            });

 

I can see that response={}
 
According to docs the response should never be empty json (i.e. it should atleast have keys for status, headers). Why is the empty json? Is there a bug?
Best Answer
0 Votes
3 REPLIES 3

Can you confirm that you requested the `access_internet` permission?

Best Answer
0 Votes

Yes, also I can confirm that my API is receiving the request and sending the response, only on the device the response is always {}

Best Answer
0 Votes

I have the exact same problem. I tried using the fetch polyfill from https://github.com/github/fetch and I get a slightly better result, I get correct looking headers in the response, with content-length indicating there should be data, but the response.json() call still returns an empty object.

Best Answer
0 Votes