使用spring web发送带有帖子数据的https发布请求 [英] sending https post request with post data using spring web

查看:130
本文介绍了使用spring web发送带有帖子数据的https发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解如何使用spring网络或其他弹簧工具发送带有帖子数据的https发布请求。

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

到目前为止我一直在使用httpclient但我正在尝试转换为spring:)

so far I've been using httpclient but i'm trying to convert to spring :)

https发布请求应该忽略自签名证书。

the https post request should ignore self signed certificate.

请提供一个如何完成的例子。

please provide an example on how it can be done.

谢谢

推荐答案

我使用Spring Integration发送http POST和GET
http://static.springsource.org/spring-integration/reference/html/http.html
需要将request-factory bean配置为允许自签名证书。
我使用以下连接声明 apacheHttpsRequestFactory 以供http Spring Integration端点使用。

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.

httpClient bean可以注入其他Spring Bean并用于发送http请求:

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

@Autowired
private HttpClient httpClient;

这是spring-intefration-context.xml的片段:

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" />

这篇关于使用spring web发送带有帖子数据的https发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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