【问题标题】:Jetty blocked by company proxyJetty 被公司代理阻止
【发布时间】:2015-03-18 19:02:06
【问题描述】:

我正在开发一个在码头 9.2.0 中运行的应用程序。 到目前为止效果很好。

现在我必须实现一个需要加载网页的功能。我正在使用此代码来加载它:

@Path( "/bla")
@GET
@Produces( MediaType.APPLICATION_JSON )
public ChildList getBla() {

    ChildList childList = new ChildList();

    String url = "http://www.google.de";
    HttpGet httpGet = new HttpGet( url ) ;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    CloseableHttpResponse response = null;
    try{
        response = httpClient.execute( httpGet );
    } catch ( Exception e ) {
        e.printStackTrace();
    }

    return childList;
}

我收到“UnknownHostException”。 我尝试使用-Dhttp.proxyHost-Dhttp.proxyPort-Dhttp.proxyUser-Dhttp.proxyPassword 启动码头。我也尝试使用System.setProperty()在上述方法中设置这些属性。

然后我尝试在 Java 控制面板中设置代理设置。

但我仍然收到“UnknownHostException”。

还有其他方法可以解决这个问题吗?

【问题讨论】:

  • 如果您尝试使用 ipaddress 会发生什么?
  • 我也得到了 UnknownHostException。
  • 在您的客户端/浏览器中,您设置代理了吗?
  • 我正在使用 fiddler 2.4.8 来测试我的应用程序。没有配置代理,因为我调用的是localhost/myapplication/bla

标签: java proxy jetty


【解决方案1】:

问题是发布的源缺少设置代理。以下代码解决了这个问题:

 HttpGet request = new HttpGet( url ) ;
 HttpHost proxy = new HttpHost( System.getProperty( "http.proxyHost" ), Integer.parseInt( System.getProperty( "http.proxyPort" ) ), "http");
 RequestConfig config = RequestConfig.custom().setProxy( proxy ).build();
 request.setConfig( config );

【讨论】:

    猜你喜欢
    • 2014-03-12
    • 2018-12-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2023-03-16
    • 2013-09-22
    • 2011-06-20
    • 1970-01-01
    相关资源
    最近更新 更多