Scikit Web

Spring Boot Http POST 통신하기 - Apache Client 본문

Backend/Spring Boot

Spring Boot Http POST 통신하기 - Apache Client

Keun0 2022. 6. 2. 08:27
728x90
반응형

Spring Boot Http Post 통신 예제 입니다.

 

apache client 를 사용하였습니다. 

 

아래 Repository 에서 개발 환경에 맞춰 라이브러리를 추가하여 사용하시면 됩니다.

https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.13

 

import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;

HttpPost reqHTTPPost = new HttpPost("http://requesturl.com");

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("parama", "test"));
params.add(new BasicNameValuePair("paramb", "tesatt"));

reqHTTPPost.setEntity(new UrlEncodedFormEntity(params));

CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(reqHTTPPost);
response.getStatusLine();
response.getEntity().getContent();
728x90
반응형

'Backend > Spring Boot' 카테고리의 다른 글

Spring Boot Http GET 통신하기 - Apache Client  (0) 2022.06.01
Comments