下面是简单的代码:
URL url = new URL(uri);
URLConnection rulConnection = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
httpUrlConnection.setDoInput(true);
httpUrlConnection.setUseCaches(false);
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.connect();
InputStreamReader isr =new InputStreamReader(httpUrlConnection.getInputStream(),"GB2312");
如果我的uri 是http://search.jd.com/Search?keyword=华为&enc=utf-8&area=2 没问题,能够读取网页内容
可是换成http://item.jd.com/827017.html 就会抛异常
java.io.IOException: Server returned HTTP response code: 400 for URL: http://item.jd.com/827017.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at ReadURL.getBufferedFromURL(ReadURL.java:12)
at ReadURL.getItemDetail(ReadURL.java:29)
at ReadURL.main(ReadURL.java:83)
java.lang.NullPointerException
请问这是为什么同一个网站的不同网址,为什么有的能访问,有的抛异常?