0
  • I am using Angular 4 / Ionic 3 for the frontend/mobile app.
  • I am using Django 1.11 for the backend.

When I try sending request from the browser as:
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Origin', '*');
this.http.post('http://0.0.0.0:8000/en/accounts/user/', {} , {headers:headers})

In my Django app I've used django-cors-headers and set:
- CORS_ORIGIN_ALLOW_ALL = True
- CORS_ALLOW_CREDENTIALS = True

From the browser I get the expected response, but when testing from mobile app the CORS request doesn't seem to pass (returns Response with status: 0 for URL: null)

 Here are the request headers when i click to send request Any suggestions on this?

lcadc17
  • 195
  • 1
  • 16
  • 1
    How looks the url which are you using from mobile? – Mariusz Sep 22 '17 at 08:54
  • It looks like you are running your browser on the development server. I can imagine that your mobile cannot access your development server. Is the URL used in your mobile version accessible? If you have the application in an accessible location and you still cannot access the API through a valid url, then you might want to check if the server does allow the OPTIONS header (preflight requests). Some tools might not have the OPTIONS header allowed by default. [link](https://stackoverflow.com/questions/46247261/cors-fails-on-request-with-options-response-with-status-0) – Nrzonline Sep 22 '17 at 09:10
  • Django server is started on 0.0.0.0:8000 Ionic is started on 0.0.0.0:8100 , if that's what your asking ? – lcadc17 Sep 22 '17 at 09:38

1 Answers1

0

Guys i guess today i'm dumb or it's friday i don't know, but the issue was the url as maybe Mariusz & Nrzonline suggested.

I've changed:
this.http.post('http://0.0.0.0:8000/en/accounts/user/', {} , to this.http.post('http://192.168.178.2:8000/en/accounts/user/', {} ,

and now it works as charm.

lcadc17
  • 195
  • 1
  • 16