Network Error with post request on iPhone


#1

Hey there - I’ve been developing with the iOS simulator and moved over to try my progress on my iPhone. When I try to log in, I don’t seem to be able to make a post request. The code is fine, as it works on the simulator, however in the device, I get a network error.

I have tried using axios (the console error I get is Error: Network Error) and fetch, where I get TypeError: Network request failed. Neither of these error messages are helpful. The output from the expo XDE is below.

Is there something else I need to do to enable post requests on the iPhone?

{"config":{"transformRequest":{},"transformResponse":{},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"},"method":"post","url":"https://localhost:3000/api/v1/users/request","data":"{\"phone\":\"redacted\"}"}}

#2

Just wondering if anybody has any ideas for this one? Much appreciated.


#3

I worked it out. I had to serve my rails server on my local IP address instead of localhost.


#4

How do you solve it? by changing the localhost to local IP address ?

I’ve server running on 127.0.0.1:8000 and in my apps I request from my api server with the address 192.168.1.97:8000 (my Mac local address).

Still it gives me network request failed.