RestTemplate .get()和.post()

问题描述 投票:-1回答:1

我正在从SOAP转换为REST。我有两个不同的测试电话。我已经找到了uri和标题,但我不知道的是.get()和.post()。我需要在REST中使用什么来实现这一目标?

public ResponseEntity<String> getGetResponse(URI uri, String wamUsername) {     
    return new Request().uri(uri)
                        .header("Accept", "application/hal+json")
                        .header("Authorization", authHeaders.getAuth())
                        .header("wam-authenticated-username", wamUsername)
                        **.get(String.class)**;
}

public ResponseEntity<?> getPostResponse(URI uri, String wamUsername, Object obj) {
    return new Request().uri(uri)
                        .header("Accept", "application/hal+json")
                        .header("Authorization", authHeaders.getAuth())
                        .header("wam-authenticated-username", wamUsername)
                        **.post(obj)**;
}
java rest soap
1个回答
0
投票
public ResponseEntity<String> getGetResponse(URI uri, String wamUsername) {   

    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "application/hal+json");
    headers.add("Authorization", authHeaders.getAuth());
    headers.add("wam-authenticated-username", wamUsername);
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    return restTemplate.exchange(uri, HttpMethod.GET, entity, String.class);

}

public ResponseEntity<?> getPostResponse(URI uri, String wamUsername, Object obj) {

    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "application/hal+json");
    headers.add("Authorization", authHeaders.getAuth());
    headers.add("wam-authenticated-username", wamUsername);
    HttpEntity<Object> entity = new HttpEntity<Object>(obj, headers);

    return restTemplate.exchange(uri, HttpMethod.POST, entity, Object.class);

}
© www.soinside.com 2019 - 2024. All rights reserved.