Http Jsonp requests work in browser, simulator, not Android Device

I have a strange issue after migrating from Heroku to another PAAS(Aptible).

When I make jsonp requests on the android device, they fail with status code 0(from what I understand - all error codes get eaten by javascript due to the nature of jsonp) and an undefined data object. The same requests to the exact same Api on my staging server(which is on heroku) work perfectly fine, with status code 200. In the browser, the requests both work fine and return a 200 from both servers. Only on the actual android device do I get this problem. This problem occurs on all android devices(I’ve tested about 6 different devices now). The request and response headers are the same for both servers. The new web server, where the problem occurs, does not even see the request in its Rails logs(although it is possible that the request gets to the server, and something is happening on the nginx server which stops the request).

Example:

$http.jsonp(
  'https://[myserver]/api/auth?callback=JSON_CALLBACK&email=[redacted]&password=[redacted]'
).
success(function(data, status, headers, config) {
  console.log("success");
  console.log("data", data);
  console.log("status", status);
  console.log("headers", headers);
  console.log("config", config);
}).
error(function(data, status, headers, config) {
  console.log("fail.");
  console.log("data", data);
  console.log("status", status);
  console.log("headers", headers);
  console.log("config", config);
});

This results in the following response on device(from Weinre):

As I said, the request and response headers are almost identical, the only differences is in two headers:
response header X-xss-protection
problem server(Aptible): X-XSS-Protection:1; mode=block
working server(Heroku): X-Xss-Protection:1; mode=block
But this shouldn’t matter, as the HTTP spec says header capitalization shouldn’t matter, so unless the device cares about this, it should be irrelevant.

Other response header differences:
problem server(Aptible): Server:Cowboy
good server(Heroku): Server:nginx/1.6.0

problem server(Aptible): Via:1.1 vegur
good server(Heroku): this header is not returned at all

Shout out to @tyvdh who has also been trying to help me debug this issue.

Are you tryin to send a post request via JSONP to avoid cross-domain things?

JSONP is only for get-requests and will not work with other request types.

@bengtler Angular’s $http.jsonp method, which I’m using, is just a GET request with the callback param handling stuff(for cross domain requests). Additionally, as I had mentioned, the same API and exact same code(both client and server side) work fine on one server but not the other.

Just a quick update on this, I’ve been working with the amazing ops team at Aptible, and we’ve found that the SSL Handshake seems to be failing, and have narrowed this down to being an issues around the SSL cert. Once we’ve figured this out, I’ll post another update.

3 Likes

Any updates on this issue?

unfortunately not, still having the same problem. I’m hoping to sort it out this week, and I will report back with my findings.

Hi, have you found a resolution for this? I have the exact same issue except that im trying to get everything to work on heroku.

Hi yanismydj.
Have you had any luck with this? I’m stuck with the exact same issue.

Thanks

I wish I could help, but I could never find a solution. I ended up hiring someone who was considered an Ionic expert, who could not find a solution. He actually urged me to go fully native, and was himself moving away from Ionic citing issues like this. Our solution ultimately was to go fully native in android and iOS, which has been arduous, but hopefully the right decision for us. I wish you all the best of luck though, and I will be curious to hear about the solution should any of you find it!

Regards!

Thanks man. I think I’m gonna hang in there. I can’t afford native. There’s always a way. I’m optimistic. Will update.

Regards,
Siphiwe

For what it’s worth, my issue was that the server SSL certificate had actually expired :blush: The server administrator sorted that out and my code started working.