在改造时禁用SPDY连接

时间:2015-05-24 16:30:28

标签: java android retrofit okhttp

我在android项目中使用改造,问题是当用户连接到代理或VPN时,HTTP REST API查询的IP地址不会因连接重用而改变。

日志显示它正在使用SPDY - OkHttp-Selected-Protocol: spdy/3.1无论如何请求改进使用HTTP 1.1或禁用连接重用/ SPDY指定路由或整个改造而不触及服务器端?

以前使用okhttp时,我会在每次调用之前使用下面的方法。 (这是一个非常糟糕的主意)

ConnectionPool pool = ConnectionPool.getDefault();
pool.evictAll();

1 个答案:

答案 0 :(得分:2)

要停用SPDY,您可以使用setProtocols

ArrayList<Protocol> protocolList = new ArrayList<Protocol>();
protocolList.add(Protocol.HTTP_1_1);

OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setProtocols(protocolList);

RestAdapter restAdapter = new RestAdapter.Builder()
    .setEndpoint(API_URL)
    .setClient(new OkClient(okHttpClient))
    .build();