0

I know how to check if my apps is connecting to wifi, and get XML string and parse it to my apps, but i want to know how to check if a site with xml ready to parse is already activate from the server so that i can get the XML and parse, because if that site is not activated from the server ill get the error "No Route to Host".

How to Check if that link is ready and activated from the server?

Dirk
  • 10,668
  • 2
  • 35
  • 49
Piolo Opaw
  • 1,471
  • 2
  • 15
  • 21
  • it will provide you with server error. Just catch an exception there. Nothing much to do with it . – Suhail Mehta Jun 05 '14 at 06:17
  • i just want to do something before an exception will happen, im required to do something before it happens in my project, should i write all status example badrequest, gatewaytimeout, forbiden, httpnotfoudn in using HttpResponse same as HttpURLConnection, or HTTP_NOT_FOUND is already enough? – Piolo Opaw Jun 05 '14 at 06:34

1 Answers1

1

When resource was not found, your web server should set response code to 404.

If you're using HttpUrlConnection

 URL url = new URL("www.example.com");
 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 if(conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND ){
    handleError(); // your custom error handler
 }
  • how about HttpResponse SC_NO_CONTENT or HttpURLConnection HTTP_NO_CONTENT? – Piolo Opaw Jun 05 '14 at 06:25
  • 204 should be used when there's a resource handler, but it returns empty response alogside with some meta-data. In your case you have a clear 404. More info here http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html –  Jun 05 '14 at 06:33
  • yup couldnt connect only "Oops! Google Chrome could not connect to " so HTTP_NOT_FOUND is enough to filter it? – Piolo Opaw Jun 05 '14 at 06:35
  • It would be enough if your web server sets response code to 404. I believe you can check this in Chrome dev tools. –  Jun 05 '14 at 06:37
  • what should i click so that i can go to chrome dev tool in the page that i open that is not valid? – Piolo Opaw Jun 05 '14 at 06:41
  • Very simple to google that, first link is http://stackoverflow.com/questions/4423061/view-http-headers-in-google-chrome –  Jun 05 '14 at 06:42
  • ok i found the tool but i the network is empty no status code appear? – Piolo Opaw Jun 05 '14 at 06:44
  • @PioloOpaw don't really get what you're asking, sorry. My best advice for you would be to contact person responsible for your web server and make sure it's configured properly. –  Jun 05 '14 at 06:46
  • ohh it appears it shows 2 status text 204 and 304 is shown so il filter the two status? – Piolo Opaw Jun 05 '14 at 06:48