版权声明:相互学习,欢迎指正,共同进步。 https://blog.csdn.net/liyuxing6639801/article/details/80618868
private String proxySet="true";
private String proxyHost="代理地址";
private String proxyPort="8080";//代理端口
private String loadJSON(String url) {
String json = null;
try {
URL mapAPI = new URL(url);
//2、创建url代理服务
InetSocketAddress address=new InetSocketAddress(proxyHost,Integer.parseInt(proxyPort));
Proxy proxy=new Proxy(Proxy.Type.HTTP,address);
URLConnection connection = mapAPI.openConnection(proxy);
isr = new InputStreamReader(connection.getInputStream(), "utf-8");
json=IOUtils.toString(isr);
} catch (Exception e) {
LOGGER.error("BaiduMapServiceImpl", e);
} finally {
try {
isr.close();
} catch (IOException e) {
LOGGER.error("BaiduMapServiceImpl", e);
}
}
return json;
}