HTTP 代理配置

如果您在代理後面,並且需要為 HTTP 出站介面卡或閘道器配置代理設定,則可以使用兩種方法之一。在大多數情況下,您可以依賴控制代理設定的標準 Java 系統屬性。否則,您可以顯式配置 HTTP 客戶端請求工廠例項的 Spring bean。

標準 Java 代理配置

您可以設定三個系統屬性來配置 HTTP 協議處理程式使用的代理設定

  • http.proxyHost:代理伺服器的主機名。

  • http.proxyPort:埠號(預設為 80)。

  • http.nonProxyHosts:應直接訪問、繞過代理的主機列表。這是一個由 | 分隔的模式列表。模式可以以 * 開頭或結尾以表示萬用字元。任何與這些模式之一匹配的主機都透過直接連線而不是透過代理進行訪問。

對於 HTTPS,可以使用以下屬性

  • https.proxyHost:代理伺服器的主機名。

  • https.proxyPort:埠號,預設值為 80。

Spring 的 SimpleClientHttpRequestFactory

如果您需要對代理配置進行更明確的控制,您可以使用 Spring 的 SimpleClientHttpRequestFactory 並配置其“proxy”屬性,如以下示例所示

<bean id="requestFactory"
    class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <property name="proxy">
        <bean id="proxy" class="java.net.Proxy">
            <constructor-arg>
                <util:constant static-field="java.net.Proxy.Type.HTTP"/>
            </constructor-arg>
            <constructor-arg>
                <bean class="java.net.InetSocketAddress">
                    <constructor-arg value="123.0.0.1"/>
                    <constructor-arg value="8080"/>
                </bean>
            </constructor-arg>
        </bean>
    </property>
</bean>
© . This site is unofficial and not affiliated with VMware.