0

protected String requestData(String url,HttpEntity headers){
    System.out.println(url);
    return new RestTemplate().exchange(url, HttpMethod.GET,headers,String.class).getBody();
}

in this code, "System.out.println(url);" print

http://data.gb.go.kr/opendata/service/rest/gbDongrak/getRecordList?numOfRows=10&pageNo=1&serviceKey=K%2FhDtuwgRPJ287yiPCY4lRN9nbdVwy6%2FqDM9BFW%2FImn7TpcqXMI%2BS4%2F6%2F5GuRyoMudE5SnR6a4xpj62S2OnIjw%3D%3D&b_year=2020&b_month=09

but "return new RestTemplate().exchange(url, HttpMethod.GET,headers,String.class).getBody(); "request wrong url

http://data.gb.go.kr/opendata/service/rest/gbDongrak/getRecordList?numOfRows=10&pageNo=1&serviceKey=K%252FhDtuwgRPJ287yiPCY4lRN9nbdVwy6%252FqDM9BFW%252FImn7TpcqXMI%252BS4%252F6%252F5GuRyoMudE5SnR6a4xpj62S2OnIjw%253D%253D&b_year=2020&b_month=09

what's wrong?

JCompetence
  • 6,997
  • 3
  • 19
  • 26
swz
  • 63
  • 6
  • https://stackoverflow.com/questions/20885521/spring-resttemplate-url-encoding Does this help. Those serviceKey, b_year, and the rest of the path parameters should be passed as part parameters, not as part of the URL.. – JCompetence Aug 23 '21 at 11:04
  • It’s double encoding the url (`%2f` -> `%252f`, I.e. the `%` is encoded when it shouldn’t be). Don’t encode the url before you pass it to the method. – BeUndead Aug 23 '21 at 11:05

0 Answers0