作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用适用于 Java 的 Http Apache 客户端,并且正在向 SteamWEB API 向 this steam link 发出请求。 .
这会导致 Http Apache 客户端出现错误:
org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at pl.edu.tirex.helper.http.Http.handleConnection(Http.java:77)
at pl.edu.tirex.helper.http.Http.get(Http.java:60)
at pl.edu.tirex.helper.http.Http.get(Http.java:64)
at pl.edu.tirex.helper.http.Http.get(Http.java:68)
at pl.edu.tirex.steamapi.steamguard.SteamGuard.fetchConfirmations(SteamGuard.java:42)
at pl.edu.tirex.steambot.SteamBOT.<init>(SteamBOT.java:93)
at pl.edu.tirex.steambot.SteamBOT.main(SteamBOT.java:56)
Caused by: org.apache.http.HttpException: steammobile protocol is not supported
at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:157)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
... 8 more
我的连接发送结果的代码:
private static final PoolingHttpClientConnectionManager CONNECTION_MANAGER = new PoolingHttpClientConnectionManager();
static
{
CONNECTION_MANAGER.setDefaultMaxPerRoute(2);
CONNECTION_MANAGER.setConnectionConfig(new HttpHost("https://steamcommunity.com/", 443, "steammobile"), ConnectionConfig.DEFAULT);
CONNECTION_MANAGER.setMaxTotal(4);
}
public static void main(String[] args)
{
HttpGet httpget = new HttpGet("url");
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).setConnectionManager(CONNECTION_MANAGER).build();
try (CloseableHttpResponse response = httpclient.execute(httpget, this.context))
{
HttpEntity entity = response.getEntity();
try (InputStream instream = entity.getContent())
{
if (handle != null)
{
if (response.getStatusLine().getStatusCode() >= 400)
{
handle.handleError(instream);
}
else
{
handle.handle(instream);
}
}
}
}
catch (HttpHostConnectException | InterruptedIOException | ClientProtocolException ignored)
{
}
}
我该如何处理这个错误?
最佳答案
这些解决方案工作正常:
private static final PoolingHttpClientConnectionManager CONNECTION_MANAGER = new PoolingHttpClientConnectionManager();
static
{
CONNECTION_MANAGER.setDefaultMaxPerRoute(2);
CONNECTION_MANAGER.setMaxTotal(4);
}
public static void main(String[] args)
{
HttpGet httpget = new HttpGet("url");
httpget.addHeader("X-Requested-With", "com.valvesoftware.android.steam.community");
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).setConnectionManager(CONNECTION_MANAGER).build();
try (CloseableHttpResponse response = httpclient.execute(httpget, this.context))
{
HttpEntity entity = response.getEntity();
try (InputStream instream = entity.getContent())
{
if (handle != null)
{
if (response.getStatusLine().getStatusCode() >= 400)
{
handle.handleError(instream);
}
else
{
handle.handle(instream);
}
}
}
}
catch (HttpHostConnectException | InterruptedIOException | ClientProtocolException ignored)
{
}
}
关于java - 不支持 Steammobile 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34299604/
我正在使用适用于 Java 的 Http Apache 客户端,并且正在向 SteamWEB API 向 this steam link 发出请求。 . 这会导致 Http Apache 客户端出现错
我是一名优秀的程序员,十分优秀!