首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不支持蒸汽移动协议

不支持蒸汽移动协议
EN

Stack Overflow用户
提问于 2015-12-15 21:20:32
回答 1查看 515关注 0票数 0

我正在使用,并针对SteamWEB API向这个蒸汽连接提出一个请求。

这将导致Http Apache客户端中的错误:

代码语言:javascript
复制
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

我的连接代码发送结果:

代码语言:javascript
复制
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)
    {

    }
}

如何处理此错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-17 17:01:16

这些解决方案工作正常:

代码语言:javascript
复制
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)
    {

    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34299604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档