来自http调用的随机禁止(403)响应

时间:2012-07-26 19:10:46

标签: android apache http

我在Android应用程序中进行了大量的http调用。 http调用在大多数情况下是同步的。每隔一段时间我就会连续获得403个禁止的响应,点击相同的URL。我在呼叫之前直接进行登录呼叫,结果是403.登录呼叫返回200 ok。 403s在更新的Android平台上也会发生更多。

我是如何创建客户的:

    // Create and initialize HTTP parameters
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 200);
    ConnPerRoute cpr = new ConnPerRoute() {
        public int getMaxForRoute(HttpRoute httpRoute) {
            return 50;
        }
    };
    ConnManagerParams.setMaxConnectionsPerRoute(params, cpr);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    // Create and initialize scheme registry 
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

    // Create an HttpClient with the ThreadSafeClientConnManager.
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    _client = new DefaultHttpClient(cm, params);

http电话:

CookieStore cookie_store = HttpSupport.getCookieStoreInstance();   
HttpContext http_context = HttpSupport.getHttpContextInstance(); 
HttpGet get = new HttpGet(StaticFields.DEVICES_RESOURCE);
http_context.setAttribute(ClientContext.COOKIE_STORE, cookie_store);
response = client.execute(get, http_context);
status_code = response.getStatusLine().getStatusCode();

我正在使用我的类HttpSupport中包含的静态CookieStore和HttpContext。

0 个答案:

没有答案