06-23-2018 03:48
06-23-2018 03:48
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
06-24-2018 20:15
06-24-2018 20:15
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.
06-25-2018 01:02
06-25-2018 01:02
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!