• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps HTTP response code

lalit_3686

Lurker
Feb 9, 2011
1
0
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");
httpconn.disconnect();
}
else
{
Log.i("coming","200 fail");
}
sleep(15000);


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.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones