1. Are you ready for the Galaxy S20? Here is everything we know so far!

HTTP response code

Discussion in 'Android Development' started by lalit_3686, Feb 9, 2011.

  1. lalit_3686

    lalit_3686 Lurker
    Thread Starter

    hi guys.....

    I am a software developer and facing problem in getting the response code from http connection. It works fine when connection is achieved successfully but doesnt work when connected is not achieved. My code is as under.

    url = new URL("http://www.google.co.in/");
    URLConnection conn = url.openConnection();
    httpconn= (HttpURLConnection)conn;
    responseCode = httpconn.getResponseCode() ;
    if(responseCode == HttpURLConnection.HTTP_OK)
    Log.i("coming","200 pass");
    Log.i("coming","200 fail");

    this code works well whee the response code is 200 but it never gives the response code 400 which it should give when not connected.

    1. Download the Forums for Android™ app!



Share This Page