404 error on mobile device but works on pc browser

落花浮王杯 提交于 2019-12-11 10:24:10

问题


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?


回答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




回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/8126205/404-error-on-mobile-device-but-works-on-pc-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!