It's not a secret anymore!*
The moose likes Sockets and Internet Protocols and the fly likes responsecode is 404 even if the server is up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "responsecode is 404 even if the server is up" Watch "responsecode is 404 even if the server is up" New topic
Author

responsecode is 404 even if the server is up

Abhishek Mhptr
Ranch Hand

Joined: Aug 09, 2009
Posts: 33
Hi All,

i need to check whether a URL is up or not.
When i try pinging through command prompt, i get proper response.

But when i try the below code, i get response as 404.

Also through rest client, i get response with proper login id and password.

i tried logging in before getting the response code like below.

But i still get the response as 404.

Am i missing something here??
Is there any other way to check the status of the URL?

Kindly provide me some inputs.

Thanks !!!


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you're getting a 404 response, that means that the server is indeed up, otherwise it couldn't give you that response.
Abhishek Mhptr
Ranch Hand

Joined: Aug 09, 2009
Posts: 33
Thanks for the quick and timely reply Paul.

As per HTTP Status Code Definitions, 404 means "Not Found".
i check for response 200, which means "Okay" and continue with rest of the code.

As my requirement is to check whether the server is up or not, what sort of response i should be looking for??

Is there any other way to handle this??

Thanking you !!!



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If the server returns any response at all, then it must have been up. But I already said that, didn't I?

Perhaps your requirements are unclear. Perhaps "up" means something more specific than just running and responding to requests? If you're looking for a 200 response then you have to send a URL which the server can find.
Abhishek Mhptr
Ranch Hand

Joined: Aug 09, 2009
Posts: 33
Thanks for the reply Paul..

I was looking for 200 response because i get this response for all other URLs.
Because of authentication error, i must be missing 200. I am not sure how to get rid of 404.

As you have suggested, now i am checking for a response from the URL.
If the response is not empty, i am continuing with the rest of the code.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Authentication problems don't lead to 404 errors but to 401 / 403 errors instead. 404 really means that the URL you are trying to open does not exist.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhishek Mhptr
Ranch Hand

Joined: Aug 09, 2009
Posts: 33
Thanks for the reply Rob.

As i have mentioned in my first post, if i ping from command prompt, i get a response.
Also through REST client with proper login id and password, i get response:200 for the same URL.

Even if i try logging in before getting the response code as mentioned in the 1st post, i get the response as 404.

I am not sure how to overcome this !!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: responsecode is 404 even if the server is up
 
Similar Threads
Trying to Redirect. 302 Error. HTTP CLIENT
Received fatal alert: handshake_failure
How to check if HttpURLConnection exists using the object, which was open before
Problem in reading Http Response Content
URL Posting and NSLOOKUP