1

This might be a dumb question...but I am trying to make my first app using phonegap and dojo. I am able to use ajax and read some data from the server. This works fine on the android emulator. I can also type the url into my desktop browser and the see the value. I am using spring with json objects.

When i type the same url into my phone web browser I get a 404 error. Can someone tell me why? I am very new to mobile development and I feel like i am missing something.

The url is public.

Thanks

UPDATE Using the same ajax call I can get to the following url http://search.twitter.com/search.json?q=bacon which returns a json file from twitter. So I don't think it is my client code. Any other ideas?

blong824
  • 3,920
  • 14
  • 54
  • 75
  • Can you included the entire http request made from the phone. – suing Nov 14 '11 at 18:56
  • It is a test server so I won't give out the full url but its basically 'http://mydomain.com/mobile/mobile/calc.json' (without quotes). It is a very basic spring app. It works fine all all my desktop browsers. Just keep getting 404 error on the mobile browser – blong824 Nov 14 '11 at 19:14
  • Double-check the url. Then check server logs. – Peter Knego Nov 14 '11 at 19:26
  • Url is fine. Doesn't look like it is making it to the server. At least not into my spring controller. – blong824 Nov 14 '11 at 19:34
  • i don't know what version of phonegap you're using. but make sure you have mydomain.com is added to your white list. phonegap automatically block all request to outside domain unless its in the white list. I don't remember on top of my head but its in the phonegap.plist and its under external something key. – atbebtg Nov 14 '11 at 23:48
  • I am testing on android. Isn't the phonegap.plist used for ios clients? – blong824 Nov 15 '11 at 15:14

4 Answers4

1

I had very similar symptoms in my current PhoneGap project. When I was trying to reach my nginx/PHP backend with a jQuery call:

var jqxhr = $.post(SERVER_URL, {'some': 'parameters', 'another': 'parameter'}, null, "jsonp")
    .done(function (data) {
            // Success, do something...
    })
    .fail(function (data) {
            // Failed, do something...
    });

...the connection failed with 404 when using SSL. If the SERVER_URL pointed to a http URL the call worked all right. There were no redirections whatsoever on the server. According to the server logs the backend was executed and it returned the correct JSON-formatted output.

The code failed only with Android 6.x (did not test earlier) but worked all right with iOS 10.x (did not test earlier) as well as Firefox and Chromium.

The reason was that my nginx configuration had following options:

add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

It appears that the other platforms did not respect these headers as the Android did.

1

wild guesses 1) your server may be expecting proper headers

Accept: application/json

web browsers uses wildcards by default (Accept: /)

2) your server maybe filtering out using ua-agent headers and rejects non-web browsers

Yilmaz Guleryuz
  • 9,313
  • 3
  • 32
  • 43
  • Thanks for the answer. I am using @ResponseBody in spring and I am using mvc:annotation-driven with jackson on my classpath. I beleive that it should set the headers to application/json automatically with this setup. I checked with my server admin and he is not filtering anything. He showed me we can hit the url from the command line on the server as well. He sees my android device requesting the same url and it sends 404 instead of 200? – blong824 Nov 14 '11 at 21:01
  • i mean the client needs to have this in its header -> Accept: application/json
    those were wild guesses as per problem description
    – Yilmaz Guleryuz Nov 15 '11 at 09:36
0

recently I faced similar problem, happens when you try to connect to http://localhost from Android emulator. see this thread which contains nice solution -> Accessing webserver running within Eclipse from outside the workstation

simple solution: when you want to access localhost from Android emulator, you should use 10.0.2.2

Community
  • 1
  • 1
Yilmaz Guleryuz
  • 9,313
  • 3
  • 32
  • 43
0

Thanks everyone for the help. It ended up being casued by nginx rerouting the mobile requests to a server where the app was not hosted. Hence the 404 errors.

blong824
  • 3,920
  • 14
  • 54
  • 75
  • 1
    can you give more details, please? seems I have a similar problem, but I don't have the required knowledge as nginx administrator – user732456 Jan 22 '19 at 13:17