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

Fetch error 400

Hello all, I am trying to post data using fetch. It appears a 400 error: Request not allowed.

I have checked headers and body and I can't solve the problem. Could anyone help me?

 


messaging.peerSocket.onmessage = function(evt) {
console.log(JSON.stringify(evt.data));
fetch('http://myserver.es:3000/mypost', {
    method:'post',
    headers: {
      'Content-Type': 'application/json'
    },
    body:JSON.stringify(evt.data)
  }).then(function(result) {
    if (!result.ok) {
      console.log(result.status + ': ' + result.statusText);
      return;
    }
    console.log('Enviado paquete');
  }).catch(function (err){
    console.log(err)
  })
}

 

Thanks all

Best Answer
0 Votes
2 REPLIES 2

Just to give you a heads up and not sure if relevant to your problem, with iOS all network requests need to be done over SSL so try HTTPS.

Best Answer

Yes, I think it is relevant, indeed I think it is the problem. I am actually using Android, not iOS, but I think it is necessary to do the network requests with https aswell. Thanks!

Best Answer
0 Votes