f



HttpURLConnection, getResponseCode=404 (HTTP_NOT_FOUND)

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());
    }
    
}

0
1/24/2006 10:51:46 PM
comp.lang.java.help 13339 articles. 0 followers. Post Follow

3 Replies
4047 Views

Similar Articles

[PageSpeed] 18

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

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

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

0
opalpa (344)
1/24/2006 11:17:20 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
0
jw2328 (121)
1/25/2006 12:40:55 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());
>    }
>
> }
> 


0
Bocanegra
1/25/2006 8:10:07 AM
Reply: