JAVA Resttemplate 을 이용해서 post 로 요청 보내기
https://howtodoinjava.com/spring-boot2/resttemplate/resttemplate-post-json-example/
@Test
public
void
testAddEmployeeWithoutHeader_success()
throws
URISyntaxException
{
RestTemplate restTemplate =
new
RestTemplate();
URI uri =
new
URI(baseUrl);
//Nodejs 에게 보낼려면 이 부분을 JSONObject 로 만들면 될듯?
Employee employee =
new
Employee(
null
,
"Adam"
,
"Gilly"
,
"test@email.com"
);
HttpHeaders headers =
new
HttpHeaders();
headers.set(
"X-COM-PERSIST"
,
"true"
);
headers.set(
"X-COM-LOCATION"
,
"USA"
);
HttpEntity<Employee> request =
new
HttpEntity<>(employee, headers);
ResponseEntity<String> result = restTemplate.postForEntity(uri, request, String.
class
);
//Verify request succeed
Assert.assertEquals(
201
, result.getStatusCodeValue());
}
댓글
댓글 쓰기