java - 不支持 Steammobile 协议(protocol)

标签 java http mobile protocols steam

我正在使用适用于 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 - 初始化后 OpenGL 窗口卡住

java - 单例类识别

javascript - Node.js中如何从客户端获取数据到服务器(不带url参数)?

在 Status Created 上设置 Location header 路径时,Javax Response 在方法路径前添加

linux - Android处理不构建程序

java - 无状态类有多少字节?

web-services - Scala - Play : how to nicely handle WS get exception

javascript - Hammer JS > 如何在页面滚动期间阻止水平平移

android - 使用手持设备在 Eclipse 中调试 Android 应用程序

java txt文件读取程序,仅读取txt文件的第一行