sending https post request with post data using spring web

前端 未结 1 823
故里飘歌
故里飘歌 2021-01-22 11:24

I\'m trying to understand how to send https post request with post data using spring web or and other spring tools.

so far I\'ve been using httpclient but i\'m trying to

相关标签:
1条回答
  • 2021-01-22 11:35

    I use Spring Integration to send http POST and GET http://static.springsource.org/spring-integration/reference/html/http.html The request-factory bean need to be configured to allow self-signed certificates. I use the following wiring to declare apacheHttpsRequestFactory to be used by http Spring Integration endpoints.

    The httpClient bean can be injected to other Spring Beans and used to send http requests:

    @Autowired
    private HttpClient httpClient;
    

    Here is the fragment of spring-intefration-context.xml:

    <!-- HTTPS connection to trust self signed certificates -->
    <bean id="sslSocketFactory" class="org.apache.http.conn.ssl.SSLSocketFactory">
        <constructor-arg name="trustStrategy">
            <bean class="org.apache.http.conn.ssl.TrustSelfSignedStrategy" />
        </constructor-arg>
        <constructor-arg name="hostnameVerifier">
            <bean class="org.apache.http.conn.ssl.AllowAllHostnameVerifier" />
        </constructor-arg>
    </bean>
    <bean id="httpsSchemaRegistry" class="org.apache.http.conn.scheme.SchemeRegistry">
        <property name="items">
            <map>
                <entry key="https">
                    <bean class="org.apache.http.conn.scheme.Scheme">
    
                        <constructor-arg value="https" />
                        <constructor-arg value="443" />
                        <constructor-arg ref="sslSocketFactory" />
                    </bean>
                </entry>
            </map>
        </property>
    </bean>
    <bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
        <constructor-arg>
            <bean class="org.apache.http.impl.conn.PoolingClientConnectionManager">
                <constructor-arg ref="httpsSchemaRegistry" />
            </bean>
        </constructor-arg>
    </bean>
    <bean id="apacheHttpsRequestFactory"
        class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
        <constructor-arg ref="httpClient" />
    
    0 讨论(0)
提交回复
热议问题