Commit ddaae8d2 by 谢海旭

查询省市优化

1 parent ec71e6cc
......@@ -9,10 +9,15 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.core.env.Environment;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
......@@ -73,9 +78,16 @@ public class ApiRegionSearchController {
log.info("regionSearch request url: {}", finalUrl);
RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject(finalUrl, String.class);
return RopResponse.success(response);
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
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) {
log.error("请求地址" + baseUrl + "出错", e);
return RopResponse.error("请求地址出错");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!