java设置代理服务器请求

public static void main(String[] args) throws Exception

    {   

        HttpClient httpClient = new HttpClient();  

        httpClient.getHostConfiguration().setProxy("xxxx"8080);  

        HttpMethod method = new GetMethod("http://java.sun.com/");

        httpClient.executeMethod(method);

        InputStream  in = method.getResponseBodyAsStream(); 

        File file = new File("D:/b.html");  

        OutputStream os = new FileOutputStream(file);  

        byte[] buff = new byte[4096];  

        int len=-1;  

        while((len=in.read(buff))!=-1){  

            os.write(buff,0,len);  

        }  

        in.close();  

        os.close();  

        method.releaseConnection();

    }   

猜你喜欢

转载自blog.csdn.net/Scarlett1994/article/details/81135578