MAC IDEA代理问题

设置了IDEA的代理,通过了check connection测试,
图片描述

但是自己写了一个HttpClient,Get测试www.google.com.hk还是没有响应,是哪里设置的有问题吗?

还需要设置什么

阅读 5.9k
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:响应的结果是一样的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题