URL url = new URL("http://134.127.20.154:8000/sc/sc?city=beijing"); URLConnection urlconn = url.openConnection(); urlconn.setDoOutput(true);
InputStream is = urlconn.getInputStream(); int b; while((b = is.read()) != -1){ System.out.print((char)b); }
谢谢 tomxutomxu(shprog) 不过 为使么运新到InputStream is = urlconn.getInputStream(); 就抛出异常: java.io.IOException: Server returned HTTP response code: 401 for URL: http://ssuzssdg/kb/index.asp
还有如何接受SERVER的响应?
URLConnection urlconn = url.openConnection();
urlconn.setDoOutput(true);
InputStream is = urlconn.getInputStream();
int b;
while((b = is.read()) != -1){
System.out.print((char)b);
}
为使么运新到InputStream is = urlconn.getInputStream();
就抛出异常:
java.io.IOException: Server returned HTTP response code: 401 for URL: http://ssuzssdg/kb/index.asp
网上见过介绍的,按图索骥吧
或者你用servlet啊,然后实现doGet()方法不就可以了吗?
这里有一个写好的HTTPClient的library,可以参考,或者干脆直接使用,还算比较好用
有源码的
你请求的那个网页需要登录认证