For Programmers: Free Programming Magazines  


Home > Archive > Java Help > January 2006 > HttpURLConnection, getResponseCode=404 (HTTP_NOT_FOUND)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HttpURLConnection, getResponseCode=404 (HTTP_NOT_FOUND)
jespersahner

2006-01-24, 7:06 pm

Hi!

I use a HttpURLConnection to connect to a website and receive a
ResponseCode=404 (HTTP_NOT_FOUND). However I have no problem opening
the website in my browser (IE).

Why the difference, and what can I do about it?

Regards,
Jesper
_____________

My program:

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class Testing {

public static void main(String[] args) throws IOException {
URL url=new URL("http://www.google.com"); // dummy-example
HttpURLConnection con=(HttpURLConnection)url.openConnection();

con.connect();
if(con.getResponseCode() == HttpURLConnection.HTTP_OK)
System.out.println("Connection established");
else System.out.println("Connection refused
"+con.getResponseCode());
}

}

opalpa@gmail.com opalinski from opalpaweb

2006-01-24, 7:06 pm

Get a variable referencing the connection, say googleconnection, and
then:

googleconnection.setRequestProperty("User-Agent","");

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/

James Westby

2006-01-24, 7:06 pm

jespersahner wrote:
> Hi!
>
> I use a HttpURLConnection to connect to a website and receive a
> ResponseCode=404 (HTTP_NOT_FOUND). However I have no problem opening
> the website in my browser (IE).
>
> Why the difference, and what can I do about it?

[snip]

It's no help, but your code works for me. At least you know that it
isn't a coding problem.

James
Bocanegra

2006-01-25, 4:14 am

What about a problem with proxy? Do you have a proxy in this net?

"jespersahner" <jespersahner@hotmail.com> escribió en el mensaje
news:1138143106.763875.160720@z14g2000cwz.googlegroups.com...
> Hi!
>
> I use a HttpURLConnection to connect to a website and receive a
> ResponseCode=404 (HTTP_NOT_FOUND). However I have no problem opening
> the website in my browser (IE).
>
> Why the difference, and what can I do about it?
>
> Regards,
> Jesper
> _____________
>
> My program:
>
> import java.io.IOException;
> import java.net.HttpURLConnection;
> import java.net.URL;
>
> public class Testing {
>
> public static void main(String[] args) throws IOException {
> URL url=new URL("http://www.google.com"); // dummy-example
> HttpURLConnection con=(HttpURLConnection)url.openConnection();
>
> con.connect();
> if(con.getResponseCode() == HttpURLConnection.HTTP_OK)
> System.out.println("Connection established");
> else System.out.println("Connection refused
> "+con.getResponseCode());
> }
>
> }
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com