Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2015 14:43
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
rest template with utf-8 text/html
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.http.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.nio.charset.Charset;
import java.util.List;
public class PortalRestTemplateIntegrationTest {
private Log logger = LogFactory.getLog(PortalRestTemplateIntegrationTest.class);
public void test() throws Exception {
RestTemplate restTemplate = new RestTemplate();
HttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
List<HttpMessageConverter<?>> httpMessageConverter = Lists.newArrayList();
URI targetUrl= UriComponentsBuilder.fromUriString("")
.queryParam("q", "잠실역")
HttpHeaders headers = new HttpHeaders();
Charset utf8 = Charset.forName("UTF-8");
MediaType mediaType = new MediaType("text", "html", utf8);
headers.set("User-Agent", "mozilla");
headers.set("Accept-Language", "ko");
// gzip 사용하면 byte[] 로 받아서, 압축을 풀고 decoding 해야 한다.
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
ResponseEntity<String> responseEntity =, HttpMethod.GET, entity, String.class);
String result = responseEntity.getBody();;
Copy link

arioss commented Sep 5, 2020

Solved my problem. Thx!!!

Copy link

worked for me, too. My solution on stackoverflow is based a bit on your code. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment