当前位置: 首页>>代码示例>>Java>>正文


Java HttpContext类代码示例

本文整理汇总了Java中cz.msebera.android.httpclient.protocol.HttpContext的典型用法代码示例。如果您正苦于以下问题:Java HttpContext类的具体用法?Java HttpContext怎么用?Java HttpContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpContext类属于cz.msebera.android.httpclient.protocol包,在下文中一共展示了HttpContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isRedirectRequested

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:MyRedirectHandler.java

示例2: sendRequest

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
  protected RequestHandle sendRequest(DefaultHttpClient client,
                                      HttpContext httpContext, HttpUriRequest uriRequest,
                                      String contentType, ResponseHandlerInterface responseHandler,
                                      Context context) {
      if (contentType != null) {
          uriRequest.addHeader(AsyncHttpClient.HEADER_CONTENT_TYPE, contentType);
      }

      responseHandler.setUseSynchronousMode(true);

/*
       * will execute the request directly
*/
      newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context).run();

      // Return a Request Handle that cannot be used to cancel the request
      // because it is already complete by the time this returns
      return new RequestHandle(null);
  }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:SyncHttpClient.java

示例3: cleanCookie

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
public static void cleanCookie() {
    // first clear store
    // new PersistentCookieStore(AppContext.getInstance()).clear();
    // clear header
    AsyncHttpClient client = CLIENT;
    if (client != null) {
        HttpContext httpContext = client.getHttpContext();
        CookieStore cookies = (CookieStore) httpContext
                .getAttribute(HttpClientContext.COOKIE_STORE);
        // 清理Async本地存储
        if (cookies != null) {
            cookies.clear();
        }
        // 清理当前正在使用的Cookie
        client.removeHeader("Cookie");
    }
    log("cleanCookie");
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:19,代码来源:ApiHttpClient.java

示例4: getClientCookie

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
/**
 * 从AsyncHttpClient自带缓存中获取CookieString
 *
 * @param client AsyncHttpClient
 * @return CookieString
 */
private static String getClientCookie(AsyncHttpClient client) {
    String cookie = "";
    if (client != null) {
        HttpContext httpContext = client.getHttpContext();
        CookieStore cookies = (CookieStore) httpContext
                .getAttribute(HttpClientContext.COOKIE_STORE);

        if (cookies != null && cookies.getCookies() != null && cookies.getCookies().size() > 0) {
            for (Cookie c : cookies.getCookies()) {
                cookie += (c.getName() + "=" + c.getValue()) + ";";
            }
        }
    }
    log("getClientCookie:" + cookie);
    return cookie;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:ApiHttpClient.java

示例5: process

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
    if (httpResponse.getStatusLine().getStatusCode() == 302) {
        final URI reqUri = ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI();
        final HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        final String url = (reqUri.isAbsolute()) ? reqUri.toString() : (currentHost.toURI() + reqUri.getPath());
        final String redirect = httpResponse.getLastHeader("Location").getValue();

        String strDate = "";
        if(url.equals(Fetcher.ROOT)) {
            strDate = CommonUtils.splitDate(pattern,redirect);
            newIssueNum = CommonUtils.dateStrToLong("yyyy-MM-dd",strDate);

        }
        Log.d(SectionFragment.class.getName(),"interceptor" + redirect + ":::" + strDate + " "+ (newIssueNum >AppContext.getLatestIssueNum()));
        Log.d(SectionFragment.class.getName(),"interceptor: " + url);
    }
}
 
开发者ID:TheHandApp,项目名称:TheHand,代码行数:19,代码来源:SectionFragment.java

示例6: process

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
    if (httpResponse.getStatusLine().getStatusCode() == 302) {
        final URI reqUri = ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI();
        final HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        final String url = (reqUri.isAbsolute()) ? reqUri.toString() : (currentHost.toURI() + reqUri.getPath());
        final String redirect = httpResponse.getLastHeader("Location").getValue();

        String pattern = "([0-9]{4}-[0-9]{2}-[0-9]{2})";
        String strDate="";
        if(url.equals(Fetcher.ROOT)) {
            strDate = CommonUtils.splitDate(pattern,redirect);
            newIssueNum = CommonUtils.dateStrToLong("yyyy-MM-dd",strDate);

        }
        Log.d("interceptor",redirect + ":::" + strDate + " "+ newIssueNum);
        Log.d("interceptor",url);
    }
}
 
开发者ID:TheHandApp,项目名称:TheHand,代码行数:20,代码来源:MainActivity.java

示例7: newAsyncHttpRequest

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    AsyncHttpRequest httpRequest = getHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
    return httpRequest == null
            ? super.newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context)
            : httpRequest;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:SampleParentActivity.java

示例8: retryRequest

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b);

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        if (currentReq == null) {
            return false;
        }
    }

    if (retry) {
        SystemClock.sleep(retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:RetryHandler.java

示例9: process

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:PreemptiveAuthorizationHttpRequestInterceptor.java

示例10: authenticate

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public Header authenticate(Credentials credentials, HttpRequest request, HttpContext httpContext)
        throws AuthenticationException {
    CharArrayBuffer buffer = new CharArrayBuffer(32);
    buffer.append(AUTH.WWW_AUTH_RESP);
    buffer.append(": Bearer ");
    buffer.append(credentials.getUserPrincipal().getName());
    return new BufferedHeader(buffer);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:BearerAuthSchemeFactory.java

示例11: handleLoginResult

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
private void handleLoginResult(LoginResult result) {
    if(result.getDataResult().isOK()) {
        AsyncHttpClient client = ApiHttpClient.getHttpClient();
        HttpContext httpContext = client.getHttpContext();
        CookieStore cookies = (CookieStore)httpContext
                .getAttribute(ClientContext.COOKIE_STORE);
        if(cookies != null) {
            String tmp_cookies = "";
            for(Cookie c : cookies.getCookies()) {
                LogUtil.log("cookie:" + c.getName() + " " + c.getValue());
                tmp_cookies += (c.getName() + "=" + c.getValue()) + ";";
                AppContext.getContext().setProperty(AppConfig.CONF_COOKIE,
                        tmp_cookies);
                ApiHttpClient.setCookie(ApiHttpClient.getCookie(AppContext
                        .getContext()));
                HttpConfig.sCookie = tmp_cookies;
            }
        }
        User user = result.getUser();
        result.getUser().setAccount(user.getUsername());
        result.getUser().setPassword(user.getPassword());
        result.getUser().setRememberMe(true);
        AppContext.getContext().saveUserInfo(user);
    }
    else {
        AppContext.getContext().cleanLoginInfo();
        ToastUtil.showToast("错误:" + result.getDataResult().getErrorMsg());
    }
}
 
开发者ID:sczyh30,项目名称:yuedong-app,代码行数:30,代码来源:LoginPresenter.java

示例12: connectSocket

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
public Socket connectSocket(
        final int connectTimeout,
        final Socket socket,
        final HttpHost host,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpContext context) throws IOException {
    Args.notNull(host, "HTTP host");
    Args.notNull(remoteAddress, "Remote address");
    final Socket sock = socket != null ? socket : createSocket(context);
    if (localAddress != null) {
        sock.bind(localAddress);
    }
    try {
        if (connectTimeout > 0 && sock.getSoTimeout() == 0) {
            sock.setSoTimeout(connectTimeout);
        }
        sock.connect(remoteAddress, connectTimeout);
    } catch (final IOException ex) {
        try {
            sock.close();
        } catch (final IOException ignore) {
        }
        throw ex;
    }
    // Setup SSL layering if necessary
    if (sock instanceof SSLSocket) {
        final SSLSocket sslsock = (SSLSocket) sock;
        sslsock.startHandshake();
        verifyHostname(sslsock, host.getHostName());
        return sock;
    } else {
        return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
    }
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:36,代码来源:ExtendedSSLSocketFactory.java

示例13: getHttpRequest

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:SampleParentActivity.java

示例14: getHttpRequest

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
@Override
public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    return new PrePostProcessRequest(client, httpContext, uriRequest, responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:PrePostProcessingSample.java

示例15: PrePostProcessRequest

import cz.msebera.android.httpclient.protocol.HttpContext; //导入依赖的package包/类
public PrePostProcessRequest(AbstractHttpClient client, HttpContext httpContext, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
    super(client, httpContext, request, responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:PrePostProcessingSample.java


注:本文中的cz.msebera.android.httpclient.protocol.HttpContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。