0

Note This Code Does work for iOS but not for Android

let data = fetch('http://mylocalapi.test/api/query?resource=article')
.then((response) => {
  console.log("Get Data");
  console.log(response);
  this.setState({articles:JSON.parse(response._bodyInit)});
});

Response Returns the Following. It seems to be trying to redirect me to dnssearch.com because it cant find my rul. My Url is a actual test domain.

I am using genymotion for the emulator and testing with Expo

12:16:23: Response {
12:16:23:   "_bodyInit": "<html><head><meta http-equiv=\"refresh\" content=\"0;url=http://www.dnsrsearch.com/index.php?origURL=http://whatshapp.test/api/query&bc=\"/></head><body><script type=\"text/javascript\">window.location=\"http://www.dnsrsearch.com/index.php?origURL=\"+escape(window.location)+\"&r=\"+escape(document.referrer)+\"&bc=\";</script></body></html>",
12:16:23:   "_bodyText": "<html><head><meta http-equiv=\"refresh\" content=\"0;url=http://www.dnsrsearch.com/index.php?origURL=http://whatshapp.test/api/query&bc=\"/></head><body><script type=\"text/javascript\">window.location=\"http://www.dnsrsearch.com/index.php?origURL=\"+escape(window.location)+\"&r=\"+escape(document.referrer)+\"&bc=\";</script></body></html>",
12:16:23:   "headers": Headers {
12:16:23:     "map": Object {
12:16:23:       "cache-control": Array [
12:16:23:         "public, max-age=0",
12:16:23:       ],
12:16:23:       "connection": Array [
12:16:23:         "close",
12:16:23:       ],
12:16:23:       "content-type": Array [
12:16:23:         "text/html",
12:16:23:       ],
12:16:23:       "date": Array [
12:16:23:         "Fri, 30 Mar 2018 16:15:49 GMT",
12:16:23:       ],
12:16:23:       "expires": Array [
12:16:23:         "Fri, 30 Mar 2018 16:15:48 GMT",
12:16:23:       ],
12:16:23:       "server": Array [
12:16:23:         "nginx",
12:16:23:       ],
12:16:23:       "transfer-encoding": Array [
12:16:23:         "chunked",
12:16:23:       ],
12:16:23:       "vary": Array [
12:16:23:         "Accept-Encoding",
12:16:23:       ],
12:16:23:     },
12:16:23:   },
12:16:23:   "ok": true,
12:16:23:   "status": 200,
12:16:23:   "statusText": undefined,
12:16:23:   "type": "default",
12:16:23:   "url": "http://whatshapp.test/api/query?resource=article",
12:16:23: }
Community
  • 1
  • 1
numerical25
  • 10,524
  • 36
  • 130
  • 209

1 Answers1

0

I've had this problem before where ios was working, but android was not when using localhost or 0.0.0.0. The solution that worked for me was to use my internal ip, as described here

user3526468
  • 334
  • 5
  • 14