String httpAddress="http://www.sina.com.cn";
URL url = new URL(httpAddress);
InetSocketAddress address = new InetSocketAddress("10.68.28.7", 808);
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
URLConnection conn = url.openConnection(proxy);InputStream inputStream = conn.getInputStream();
InputStreamReader InputStreamReader = new InputStreamReader(inputStream,
"GBK");
BufferedReader rd = new BufferedReader(InputStreamReader);
System.out.println("连接成功。");得到的URLConnection 不 为 null,conn的inputStream属性为null。。执行InputStream inputStream = conn.getInputStream();时候,返回java.io.IOException: Server returned HTTP response code: 400 for URL: http://www.sina.com.cn
大虾给看一下
URL url = new URL(httpAddress);
InetSocketAddress address = new InetSocketAddress("10.68.28.7", 808);
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
URLConnection conn = url.openConnection(proxy);InputStream inputStream = conn.getInputStream();
InputStreamReader InputStreamReader = new InputStreamReader(inputStream,
"GBK");
BufferedReader rd = new BufferedReader(InputStreamReader);
System.out.println("连接成功。");得到的URLConnection 不 为 null,conn的inputStream属性为null。。执行InputStream inputStream = conn.getInputStream();时候,返回java.io.IOException: Server returned HTTP response code: 400 for URL: http://www.sina.com.cn
大虾给看一下
解决方案 »
- java连接sql server 2005
- 关于myeclipse调试java网络程序的问题!就高手指点!
- 关于在jscrollpane中添加jtable的问题
- 这个Socket程序错在哪里?(新手急求助)
- 想开始学JAVA,看到两本书,不知选那本.请各位谈谈
- 麻烦大家解释一下代码Queue谢谢.
- 我在applet里弹出一个窗口(window或JFrame),可是窗体底部总是带有一行文字:Java Applet Window,我的窗体并没有加入这个,为什么Apple
- applet与servlet通信的问题
- 架构和框架是不是一个概念?
- jdbc链接oracle,查询数据时出错
- 如何去覆写equals()方法呢?
- jcreator 4.0中用Basic Java Application建立工程问题!!!!
400 表示:错误请求
你的请求没有对应服务 服务器没有向客户端写东西
你客户端conn.getInputStream()就是null了
try{
URL url = new URL(location);
BASE64Encoder encoder = new BASE64Encoder();
String auth = "Basic"+encoder.encode("username:password".getBytes());
System.getProperties().put("proxySet","true");
System.getProperties().put("proxyHost","ip_address");
System.getProperties().put("proxyPort","端口,如:8080");
URLConnection connection = url.openConnection();
connection.setRequestProperty("Proxy-Authorization",auth);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
}catch(Exception e){
e.printStackTrace();
}