Example usage for org.apache.http.client.methods HttpUriRequest setHeaders

List of usage examples for org.apache.http.client.methods HttpUriRequest setHeaders

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpUriRequest setHeaders.

Prototype

void setHeaders(Header[] headerArr);

Source Link

Usage

From source file:com.lxh.util.http.LXH_HttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated
 * the request with customized headers//from w w  w  .j av  a  2  s .c  o m
 * 
 * @param url
 *            the URL to send the request to.
 * @param headers
 *            set headers only for this request
 * @param params
 *            additional GET parameters to send with the request.
 * @param responseHandler
 *            the response handler instance that should handle the response.
 *            ?HTTP GET,?Android? 
 * 
 * @param url
 *            ??URL?
 * @param? 
 * @param? ????
 * @param responseHandler
 *            ???????
 */
public void get(Context context, String url, Header[] headers, RequestParams params,
        LXH_HttpResponseHandler responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
    if (headers != null)
        request.setHeaders(headers);
    sendRequest(context, httpClient, httpContext, request, null, responseHandler, context);
}

From source file:cn.edu.zzu.wemall.http.AsyncHttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated
 * the request with customized headers/*ww  w  . j a va  2  s .c  om*/
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional GET parameters to send with the request.
 * @param responseHandler the response handler instance that should handle
 *                        the response.
 */
public RequestHandle get(Context context, String url, Header[] headers, RequestParams params,
        AsyncHttpResponseHandler responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null)
        request.setHeaders(headers);
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:cn.edu.zzu.wemall.http.AsyncHttpClient.java

/**
 * Perform a HTTP HEAD request and track the Android Context which initiated
 * the request with customized headers//from www .  ja v a 2 s.co  m
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional HEAD parameters to send with the request.
 * @param responseHandler the response handler instance that should handle
 *                        the response.
 */
public RequestHandle head(Context context, String url, Header[] headers, RequestParams params,
        AsyncHttpResponseHandler responseHandler) {
    HttpUriRequest request = new HttpHead(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null)
        request.setHeaders(headers);
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:com.enjoy.nerd.http.AsyncHttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers/*from ww w .  j  av a 2 s . c o m*/
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional GET parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle get(Context context, String url, Header[] headers, RequestParams params,
        ResponseHandlerInterface responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null)
        request.setHeaders(headers);
    SyncBasicHttpContext httpContext = new SyncBasicHttpContext(mBasicHttpContext);
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:com.enjoy.nerd.http.AsyncHttpClient.java

/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers//from  w w  w .  ja v a  2s  . c  o  m
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional HEAD parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle head(Context context, String url, Header[] headers, RequestParams params,
        ResponseHandlerInterface responseHandler) {
    HttpUriRequest request = new HttpHead(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null)
        request.setHeaders(headers);
    SyncBasicHttpContext httpContext = new SyncBasicHttpContext(mBasicHttpContext);
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:com.flyn.net.asynchttp.AsyncHttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated
 * the request with customized headers/* w ww  .  ja v a2  s.  com*/
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional GET parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle get(Context context, String url, Header[] headers, RequestParams params,
        ResponseHandlerInterface responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null) {
        request.setHeaders(headers);
    }
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:com.flyn.net.asynchttp.AsyncHttpClient.java

/**
 * Perform a HTTP HEAD request and track the Android Context which initiated
 * the request with customized headers/*from ww  w  .j  a  va2  s.c om*/
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional HEAD parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle head(Context context, String url, Header[] headers, RequestParams params,
        ResponseHandlerInterface responseHandler) {
    HttpUriRequest request = new HttpHead(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null) {
        request.setHeaders(headers);
    }
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:cn.com.loopj.android.http.AsyncHttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers/*w ww  .  j  a  v a2  s  .c  om*/
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional GET parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle get(Context context, String url, Header[] headers, RequestParams params,
        ResponseHandlerInterface responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null)
        request.setHeaders(headers);
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:cn.com.loopj.android.http.AsyncHttpClient.java

/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers/*w  ww  . j  a v a  2s  .  c  o m*/
 *
 * @param context         Context to execute request against
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional HEAD parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle head(Context context, String url, Header[] headers, RequestParams params,
        ResponseHandlerInterface responseHandler) {
    HttpUriRequest request = new HttpHead(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
    if (headers != null)
        request.setHeaders(headers);
    return sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}

From source file:jp.mixi.android.sdk.MixiContainerImpl.java

/**
 * ????//from w  ww  .jav a2 s .c  o  m
 * 
 * @param method ?http
 * @param listener ???
 * @param doRetry ????
 * @return ????
 * @throws FileNotFoundException
 * @throws MalformedURLException
 * @throws IOException
 * @throws JSONException
 * @throws RemoteException
 * @throws ApiException
 */
private String request(HttpUriRequest method, final CallbackListener listener, boolean doRetry)
        throws FileNotFoundException, MalformedURLException, IOException, JSONException, RemoteException,
        ApiException {
    HttpClient client = getHttpClient();
    HttpEntity entity = null;
    try {
        if (getAccessExpiresIn() < System.currentTimeMillis() + mSocketTimeout + mConnectionTimeout) {
            refreshToken();
        }
        method.setHeaders(getCommonHeaders());
        HttpResponse res = client.execute(method);
        StatusLine status = res.getStatusLine();
        entity = res.getEntity();

        // gzip??????
        if (isGZipEntity(entity)) {
            entity = decompressesGZipEntity(entity);
        }
        String responseBody = null;
        switch (status.getStatusCode()) {
        case HttpStatus.SC_OK:
        case HttpStatus.SC_CREATED:
            // OK?string?????
            Log.v(TAG, "HTTP OK");
            return EntityUtils.toString(entity, HTTP.UTF_8);
        case HttpStatus.SC_UNAUTHORIZED:
            if (isExpiredToken(res, status) && doRetry) {
                refreshToken();
                entity.consumeContent();
                entity = null;
                return request(method, listener, false);
            }
            responseBody = EntityUtils.toString(entity, HTTP.UTF_8);
            if (responseBody != null && responseBody.length() > 0) {
                throw new ApiException(status, responseBody);
            } else {
                throw new ApiException(status, status.getReasonPhrase());
            }
        default:
            responseBody = EntityUtils.toString(entity, HTTP.UTF_8);
            if (responseBody != null && responseBody.length() > 0) {
                throw new ApiException(status, responseBody);
            } else {
                throw new ApiException(status, status.getReasonPhrase());
            }
        }
    } finally {
        // 
        if (entity != null) {
            entity.consumeContent();
        }
        if (method != null) {
            method.abort();
        }
    }
}