@
rabbirbot00 大佬我买了个国外的 ip 设置了代理,连接到是不超时了,现在又 Connection reset 了
package com.example.demo;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
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.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@
SpringBootTestclass DemoApplicationTests {
@
Test public void testGet1() {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
String urlStr = "
https://steamcommunity.com/profiles/76561198426206369/inventory/json/730/2";
HttpGet httpGet = new HttpGet(urlStr);
httpGet.addHeader("User-Agent" ,"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45");
ResponseHandler responseHandler;
String ip = "150.109.186.75";
int port = **;
HttpHost proxy = new HttpHost(ip, port);
RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
httpGet.setConfig(requestConfig);
CloseableHttpResponse response = null;
try {
response = closeableHttpClient.execute( httpGet);
HttpEntity entity = response.getEntity();
String s = EntityUtils.toString(entity, StandardCharsets.UTF_8);
System.out.println(s);
EntityUtils.consume(entity);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (closeableHttpClient != null) {
try {
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (response != null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
2021-03-12 18:29:08.185 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {tls}->http://150.109.186.75:**->
https://steamcommunity.com:443: Connection reset
2021-03-12 18:29:08.185 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : Retrying request to {tls}->http://150.109.186.75:6396->
https://steamcommunity.com:4432021-03-12 18:29:08.280 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {tls}->http://150.109.186.75:**->
https://steamcommunity.com:443: Connection reset
2021-03-12 18:29:08.280 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : Retrying request to {tls}->http://150.109.186.75:6396->
https://steamcommunity.com:4432021-03-12 18:29:08.382 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {tls}->http://150.109.186.75:**->
https://steamcommunity.com:443: Connection reset
2021-03-12 18:29:08.382 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : Retrying request to {tls}->http://150.109.186.75:6396->
https://steamcommunity.com:443java.net.SocketException: Connection reset