Add header in http request Ionic 3

Asked

Viewed 97 times

0

I’m having trouble sending headers, when I put the headers does not work in APK, only in the browser, but if I take the lines and send no header it works normally.

In the browser works the 2 examples, on the mobile only works the second image, do not know if it is CORS pq I can not give an Alert in the request...

The code: https://pastebin.com/nQY7Gz8e

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

1 answer

0

It is normal for developers to fall into this problem, it happens because your application tries to access something external a "the api url" and to protect you from an external access it blocks this request.

but why does the browser work? I bet the api and browser are running on the same PC so the request is not blocked.

To understand more about CORS : HTTP Access Control

Some possible solutions may be:

  • Send Parameters by Headers during the requisition => { Access-Control-Allow-Origin: * }
  • Add a proxy to consume the api.
  • Use the Lib CORS in api

I hope I’ve helped :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.