java - MAC IDEA代理问题
PHP中文网
PHP中文网 2017-04-18 10:35:12
[Java讨论组]
PHP中文网
PHP中文网

认证0级讲师

全部回复(2)
迷茫

IDEA设置的代理只是对这个编辑器有效的,如果你写的程序需要使用代理的话需要在程序中设置使用代理,这个与IDEA的配置是无关的。

迷茫

@mylxsw

public class Test {

    public static void main(String[] args) {
        String url = "https://www.google.com.hk";
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setProxy("127.0.0.1", 8086);
        //创建GET方法的实例
        GetMethod getMethod = new GetMethod(url);
        //使用系统提供的默认的恢复策略
        getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler());
        try {
            client.executeMethod(getMethod);
        } catch (IOException e) {
            e.printStackTrace();
        }
        byte[] bytes = new byte[0];
        try {
            bytes = getMethod.getResponseBody();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(new String(bytes, Charset.forName("UTF-8")));
    }
}

设置了代理,但是报了下面的错,不过感觉这里的错好像是https的错

java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:127)
    at org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodBase.java:690)
    at org.apdplat.qa.datasource.Test.main(Test.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

不过url改成http:响应的结果是一样的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号