Spring Boot 中的代理设置 [英] Proxy settings in Spring Boot

查看:60
本文介绍了Spring Boot 中的代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要从网络中获取一个 XML 文件,如下所示:

My application needs to fetch an XML file from the web, as follows:

@Bean
public HTTPMetadataProvider metadataProvider()
        throws MetadataProviderException {
    String metadataURL = "http://idp.ssocircle.com/idp-meta.xml";
    final Timer backgroundTaskTimer = new Timer(true);
    HTTPMetadataProvider provider = 
            new HTTPMetadataProvider(backgroundTaskTimer, httpClient(), metadataURL);
    provider.setParserPool(parserPool());
    return provider;
}

我使用过滤网络工作,因此应用无法检索该文件.

I'm working by using a filtered network, thus the app is unable to retrieve that file.

有没有办法在 Spring Boot 中设置 HTTP 代理(例如 myproxy.eu:8080)?

There is a way to setup an HTTP Proxy (e.g. myproxy.eu:8080) in Spring Boot?

或者,我可以使用 HTTPS 协议检索 XML 文件,但我应该正确设置元数据提供程序以支持加密连接......如何?

Alternatively, I could retrieve the XML file by using the HTTPS protocol, but I should properly setup the metadata provider in order to support an encrypted connection... How?

推荐答案

这不是你可以在 spring boot 中配置的东西,HttpClient 没有使用 java 变量.

This is not something you can configure in spring boot, HttpClient is not using java variables.

因此您需要手动在 httpClient 上设置代理:

Therefor you need to set the proxy on the httpClient manually:

HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setProxyHost(new ProxyHost("your.proxy.host", 8080));
httpClient.setHostConfiguration(hostConfig);

这篇关于Spring Boot 中的代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆