Read content from URL with an http response code=204
I am trying to read from a website, and the server returns a response code of 204, which is supposed to mean there is no content, despite that the site has content. What is going on? And is there any way to access the html of a site with a 204 response code, to ignore the response code, or at least to get around it in some way?
Re: Read content from URL with an http response code=204
How do you know the site has content? Without more information - code, the site you are accessing, etc...it is difficult to troubleshoot.
Re: Read content from URL with an http response code=204
I know there's content because if i go on the web manually and view source on my browser, i can see the html.
Re: Read content from URL with an http response code=204
URL hef=new URL(my website);
BufferedReader kj=null;
int kjkj=((HttpURLConnection)hef.openConnection()).get ResponseCode();
System.out.println(kjkj);
String j=((HttpURLConnection)hef.openConnection()).getRes ponseMessage();
System.out.println(j);
URLConnection g=hef.openConnection();
g.connect();
try{
kj=new BufferedReader(new InputStreamReader(g.getInputStream()));
while(kj.readLine()!=null)
{
String y=kj.readLine();
System.out.println(y);
}
}
finally
{
if(kj!=null)
{
kj.close();
}
}
}
}
Re: Read content from URL with an http response code=204
Some sites (again you do not mention which site you wish to access, so no one can reproduce your problem to troubleshoot) require appropriate headers to be sent. Try setting certain headers, for example the User agent header corresponding to your browser (google these keywords for more information on how to do this - lots of code snippets out there)
Re: Read content from URL with an http response code=204
Quote:
Originally Posted by
doWhile
Some sites (again you do not mention which site you wish to access, so no one can reproduce your problem to troubleshoot) require appropriate headers to be sent. Try setting certain headers, for example the User agent header corresponding to your browser (google these keywords for more information on how to do this - lots of code snippets out there)
This helps very much. Thanks.