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
大虾给看一下
解决方案 »
- 求助,下面的代码如果重构
- fatal exception occurred program will exit
- java如何读写pdf文件,并转化成二进制文件。
- 我用jdom读取xml文件,除引入jdom.jar包外,是否还需要引入xerces.jar包?该问题困惑好几天了,请高手解答,先谢了
- 新手求助:关于javah的问题
- LinkedList的一点疑惑
- 一个TextListener的问题????
- 怎样把.jar弄成.exe文件,急!!!!!!!!!!!!!!
- Java 版没有MM的GG,DD.祝大家过一个安静祥和的平安夜!
- java jpanel中如何导入一个绘制好的矢量图,实现放大缩小,移动
- 如何去覆写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();
}