복붙노트

[SPRING] 스프링 웹을 사용하여 게시물 데이터와 함께 https 게시물 요청 보내기

SPRING

스프링 웹을 사용하여 게시물 데이터와 함께 https 게시물 요청 보내기

스프링 웹 또는 기타 스프링 도구를 사용하여 게시물 데이터로 https 게시물 요청을 보내는 방법을 이해하려고합니다.

지금까지 나는 httpclient를 사용하고 있었지만 봄으로 변환하려고합니다 :)

https 게시물 요청은 자체 서명 인증서를 무시해야합니다.

그것이 어떻게 행해질 수 있는지에 대한 예를 제공해주십시오.

고맙습니다

해결법

  1. ==============================

    1.나는 Spring Integration을 사용하여 http POST와 GET을 보낸다. http://static.springsource.org/spring-integration/reference/html/http.html 요청 - 팩토리 bean은 자체 서명 인증서를 허용하도록 구성되어야합니다. 다음 연결을 사용하여 apacheHttpsRequestFactory를 http Spring 통합 끝점에서 사용하도록 선언합니다.

    나는 Spring Integration을 사용하여 http POST와 GET을 보낸다. http://static.springsource.org/spring-integration/reference/html/http.html 요청 - 팩토리 bean은 자체 서명 인증서를 허용하도록 구성되어야합니다. 다음 연결을 사용하여 apacheHttpsRequestFactory를 http Spring 통합 끝점에서 사용하도록 선언합니다.

    httpClient 빈은 다른 Spring 빈에 주입되어 http 요청을 보내는 데 사용될 수있다.

    @Autowired
    private HttpClient httpClient;
    

    다음은 spring-integration-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" />
    
  2. from https://stackoverflow.com/questions/17806054/sending-https-post-request-with-post-data-using-spring-web by cc-by-sa and MIT license