Commit ddaae8d2 by 谢海旭

查询省市优化

1 parent ec71e6cc
...@@ -9,10 +9,15 @@ import io.swagger.annotations.Api; ...@@ -9,10 +9,15 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
...@@ -73,9 +78,16 @@ public class ApiRegionSearchController { ...@@ -73,9 +78,16 @@ public class ApiRegionSearchController {
log.info("regionSearch request url: {}", finalUrl); log.info("regionSearch request url: {}", finalUrl);
RestTemplate restTemplate = new RestTemplate(); try {
String response = restTemplate.getForObject(finalUrl, String.class); CloseableHttpClient httpClient = HttpClients.createDefault();
return RopResponse.success(response); HttpGet httpGet = new HttpGet(urlBuilder.toString());
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
return RopResponse.success(EntityUtils.toString(response.getEntity()));
}
} catch (IOException e) {
log.error("请求地址" + finalUrl + "出错", e);
return RopResponse.error("请求地址出错");
}
} catch (Exception e) { } catch (Exception e) {
log.error("请求地址" + baseUrl + "出错", e); log.error("请求地址" + baseUrl + "出错", e);
return RopResponse.error("请求地址出错"); return RopResponse.error("请求地址出错");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!