1

I'm having this annoying problem while trying to make a web app for an SMS Eagle. I am trying to send an API request to the SMS Eagle server, to then send the SMS, which is succesful, but the only problem is that I can't seem to be able to get the response body.

In Javascript when I look at the response body property, the value is 'null'. But when I look in the network tab, I see the value. Notice how there is also 'status: 0' and other values that seem weird. Empty response body Non empty response body in network tab

I have tried getting the value with response.json(), response.text(), response.blob() etc.. What am I doing wrong here? I have already tried multiple content-type headers too. This is my code:

fetch(`http://x.x.x.x/http_api/send_sms?login=${login_g}&pass=${pass_g}&message=${encodeURIComponent(message)}&to=${number}`, { method: 'GET', mode: 'no-cors', headers: { 'Content-Type': 'text/plain'}})
                    .then(response => response.text())
                    .then(data => console.log(data));

These are the response headers from the server: Server response headers

Kind regards, Jasper

Jasper B
  • 346
  • 3
  • 17
  • 3
    You've set the mode of the request to `no-cors` which means that the response will be Opaque (also seen in Response type) and hence you cannot read it from Javascript. You can read this answer for more details - https://stackoverflow.com/questions/36292537/what-is-an-opaque-response-and-what-purpose-does-it-serve – thanatonian2311 Jul 26 '21 at 08:04
  • 1
    If you run into CORS errors without the `mode: no-cors` you can check out [No 'Access-Control-Allow-Origin' header present](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i) – Reyno Jul 26 '21 at 08:06
  • Alright thanks for the help, will check them out and try! – Jasper B Jul 26 '21 at 08:08
  • 1
    If the server end generates a 400 error etc, then your `then` is not going to trigger, you might want to also use `catch`.. – Keith Jul 26 '21 at 08:10

0 Answers0