From 2480af577b5c930fdfbe1cd3f94e611bccb6b5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=88=9A?= <53732908@qq.com> Date: Thu, 13 Feb 2025 21:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20RestTemplateTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/pmml/RestTemplateTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ddp/ddp-runner-api/src/test/java/pmml/RestTemplateTest.java diff --git a/ddp/ddp-runner-api/src/test/java/pmml/RestTemplateTest.java b/ddp/ddp-runner-api/src/test/java/pmml/RestTemplateTest.java new file mode 100644 index 0000000..f46fdd2 --- /dev/null +++ b/ddp/ddp-runner-api/src/test/java/pmml/RestTemplateTest.java @@ -0,0 +1,46 @@ +package pmml; + + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +public class RestTemplateTest { + + public static void main(String[] args)throws Exception{ + + RestTemplate rt = new RestTemplate(); + + MultiValueMap map= new LinkedMultiValueMap<>(); + map.add("name", "tiger"); + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + // 创建HTTP实体 + HttpEntity> request = new HttpEntity<>(map, headers); + + // 发送POST请求 + String url = "http://47.99.93.74:8090/mockapi/hello2"; + String response = rt.postForObject(url, request, String.class); + + System.out.println(response); + + + ResponseEntity responseEntity = rt.postForEntity(url, request, String.class); + System.out.println(responseEntity.getBody()); + + + + + + + + + } +}