Skip to content Skip to sidebar Skip to footer

Android Http Request Wierd 404 Not Found Issue

In my application, I am trying to hit a URL which I do using the following code try { url = new URL(serverURL); httpURLConnection = (HttpURLConnection) url.openConne

Solution 1:

Are you sure that you have the android.permission.INTERNET declared in your AndroidManifext.xml?

Solution 2:

Problem solved :)

try {

            url = newURL(serverURL);

            Log.i(LOG_TAG, url+"");
            HttpGet method= newHttpGet(newURI(serverURL));
            HttpClientclient=newDefaultHttpClient();
            HttpGetrequest=newHttpGet();
            request.setURI(newURI(serverURL));
            HttpResponseresponse= client.execute(method);
            responseCode = response.getStatusLine().getStatusCode();

            Log.i(LOG_TAG,"Response code response "+response);
            Log.i(LOG_TAG,"Response responseCode "+responseCode);
        } catch (Exception e) {
            e.printStackTrace();
        }

Solution 3:

Actually you don't even need following two lines in your code.

HttpGetrequest=newHttpGet();
request.setURI(newURI(serverURL));

One HttpGet is enough and you don't need it twice.

Solution 4:

Not sure if this matters but I had the exact problem.

I was doing some explicity port 80 stuff and removing this line made it work:

HttpHosthost=newHttpHost(targetHost, 80, "http");

Post a Comment for "Android Http Request Wierd 404 Not Found Issue"