不支持Steammobile协议

时间:2015-12-15 21:20:32

标签: java http mobile protocols steam

我正在使用Http Apache Client for Java,并正在向this steam link提出针对SteamWEB API的请求。

这导致Http Apache Client出错:

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)
    {

    }
}

我如何处理此错误?

1 个答案:

答案 0 :(得分:2)

这些解决方案正常运行:

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)
    {

    }
}