user1992824
user1992824

Reputation: 11

HTTPURLConnection.getContent java.io.FileNotFoundException

I use a HttpURLConnection to connect to a website and receive an 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?

This is my Program:

String responseMsg = "";

String cgsUrl = "http://localhost:9081/ntes/";

URL url = new URL(cgsUrl);
System.out.println("ouuuuuuu-->"+url.getContent());

InputStream in = url.openConnection().getInputStream();

StringBuffer respDataBuf = new StringBuffer();
respDataBuf.setLength(0);
int b = -1;

while((b = in.read()) != -1) {
    respDataBuf.append((char)b);
}
responseMsg = respDataBuf.toString();

Upvotes: 1

Views: 2050

Answers (1)

Grooveek
Grooveek

Reputation: 10094

If this is a 404 error, this is certainly a particular server configuration.

Maybe your user-agent is banned, or you're not carrying special headers and so on. I recommend you copying the headers from your browser (all of them) and use them to make the request in your Java program.

Then you throw them away one by one to find the one which is mandatory

Upvotes: 1

Related Questions