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
大虾给看一下

解决方案 »

  1.   

    HTTP   response   code:   400
    400 表示:错误请求
    你的请求没有对应服务 服务器没有向客户端写东西 
    你客户端conn.getInputStream()就是null了
      

  2.   

    这个没试过,有这样一种用法,肯定可用,呵呵
    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();
    }