Java Code Examples for org.apache.http.client.methods.HttpUriRequest#setHeaders()

The following examples show how to use org.apache.http.client.methods.HttpUriRequest#setHeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractProtocolTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is the main entry point for subclasses.
 * This method sends a request to the server, as set up
 * by setABC methods, and returns the string send back to the client.
 * @param paramValues This is an even number of param [=] value pairs. Multiple values for the same param are supported.
 *    These are passed to the server either as URL query params, or as URL encoded values in the body if the method
 *    {@link #setMethodisPostUrlEncodedData()} has been called.
 * @return the data returned by the server.
 * @throws IOException
 */
protected String serviceRequest(final String ... paramValues) throws IOException {
	HttpUriRequest req;
	responseContentType = null;
	try {
		try {
			req = requestFactory.createRequest(paramValues);
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
		req.setHeader("Accept", accept==null?"*":accept);
		
		if(headers != null) {
			req.setHeaders(headers);
		}
		
		final HttpResponse resp = client.execute(req);
		String page="";
		final HttpEntity entity = resp.getEntity();
		if (entity != null ) {
			String encoding = "utf-8";
			assertNotNull("Entity in " + resp.getStatusLine().getStatusCode()+" response must specify content type",entity.getContentType());
			final Matcher m = charset.matcher(entity.getContentType().getValue());
			if (m.find()) {
				encoding = m.group(1);
			}
			page = QueryServlet.readFully(new InputStreamReader(entity.getContent(),encoding));
			responseContentType = entity.getContentType().getValue();
		}
		if ( resp.getStatusLine().getStatusCode()>=(permit400s?500:400) ) {
			fail(resp.getStatusLine().toString()+"\n"+ page);
		}
		return page;
	}
	finally {
		resetDefaultOptions();
	}
}
 
Example 2
Source File: AsyncHttpClient.java    From letv with Apache License 2.0 5 votes vote down vote up
public void get(Context context, String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
    if (headers != null) {
        request.setHeaders(headers);
    }
    sendRequest(this.httpClient, this.httpContext, request, null, responseHandler, context);
}
 
Example 3
Source File: FinalHttp.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
public Object getSync( String url, Header[] headers, AjaxParams params) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
    if(headers != null) request.setHeaders(headers);
    return sendSyncRequest(httpClient, httpContext, request, null);
}
 
Example 4
Source File: FinalHttp.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
public void get( String url, Header[] headers, AjaxParams params, AjaxCallBack<? extends Object> callBack) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
    if(headers != null) request.setHeaders(headers);
    sendRequest(httpClient, httpContext, request, null, callBack);
}
 
Example 5
Source File: AsyncHttpClient.java    From Android-Basics-Codes with Artistic License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 6
Source File: AsyncHttpClient.java    From Libraries-for-Android-Developers with MIT License 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 7
Source File: AsyncHttpClient.java    From Roid-Library with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which
 * initiated the request with customized headers
 * 
 * @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 void get(Context context, String url, Header[] headers, RequestParams params,
        AsyncHttpResponseHandler responseHandler) {
    HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
    if (headers != null)
        request.setHeaders(headers);
    sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}
 
Example 8
Source File: AsyncHttpClient.java    From Android-Basics-Codes with Artistic License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 9
Source File: AsyncHttpClient.java    From Android-Basics-Codes with Artistic License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 10
Source File: AsyncHttpClient.java    From Android-Basics-Codes with Artistic License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 11
Source File: AsyncHttpClient.java    From Android-Basics-Codes with Artistic License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 12
Source File: AsyncHttpClient.java    From Android-Basics-Codes with Artistic License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 13
Source File: AsyncHttpClient.java    From android-project-wo2b with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 14
Source File: AsyncHttpClient.java    From android-project-wo2b with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 15
Source File: AsyncHttpClient.java    From sealtalk-android with MIT License 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 16
Source File: AsyncHttpClient.java    From sealtalk-android with MIT License 3 votes vote down vote up
/**
 * Perform a HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 17
Source File: AsyncHttpClient.java    From AndroidWear-OpenWear with MIT License 3 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated
 * the request with customized headers
 *
 * @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);
}
 
Example 18
Source File: AsyncHttpClient.java    From Mobike with Apache License 2.0 3 votes vote down vote up
/**
 * Perform getUrl HTTP GET request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 19
Source File: AsyncHttpClient.java    From Mobike with Apache License 2.0 3 votes vote down vote up
/**
 * Perform getUrl HTTP HEAD request and track the Android Context which initiated the request with
 * customized headers
 *
 * @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);
}
 
Example 20
Source File: SyncHttpClient.java    From sealtalk-android with MIT License 2 votes vote down vote up
/**
 * Perform a HTTP GET request and track the Android Context which initiated
 * the request with customized headers
 * 
 * @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.
 * @return String
 * @throws HttpException
 */
public String get(Context context, String url, Header[] headers, RequestParams params) throws HttpException {
	HttpUriRequest request = new HttpGet(getUrlWithQueryString(isUrlEncodingEnabled, url, params));
	if (headers != null)request.setHeaders(headers);
	return sendRequest(httpClient, httpContext, request, null, context);
}