我正在尝试使用java.net
包类读取网站。该网站有内容,我在浏览器的html源代码工具中手动查看。当我得到响应代码并尝试使用java查看站点时,它会成功连接,但会将站点解释为没有内容的站点(204代码)。这是怎么回事,是否有可能解决这个问题来自动查看html。是否可以通过java.net访问204响应代码的站点的html?
感谢您的回复: 您是否需要该网址?
这里是代码:
URL hef=new URL(the website);
BufferedReader kj=null;
int kjkj=((HttpURLConnection)hef.openConnection()).getResponseCode();
System.out.println(kjkj);
String j=((HttpURLConnection)hef.openConnection()).getResponseMessage();
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();
}
}
}
你可以发布代码吗? – Joe