Android HttpUriRequest - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HttpUriRequest class.

This code example shows how to use the following methods:addHeader
 
 
    // Private stuff 
    protected void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, AsyncHttpResponseHandler responseHandler, Context context) {
        if(contentType != null) {
            uriRequest.addHeader("Content-Type", contentType);
        } 
 
        Future<?> request = threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler));
 
        if(context != null) {
            // Add request to request map 
            List<WeakReference<Future<?>>> requestList = requestMap.get(context);
            if(requestList == null) {
                requestList = new LinkedList<WeakReference<Future<?>>>();
                requestMap.put(context, requestList);
            } 
 
            requestList.add(new WeakReference<Future<?>>(request));
 
7
CodeRank
This code example shows how to use the following methods:getURI
		} 
	} 
 
	private void addAccessTokenToHttpUriRequest(HttpUriRequest httpUriRequest) {
		if (mEncodedAccessToken != null) {
			String query = httpUriRequest.getURI().getQuery();
	 
			if (query == null || query.length() == 0) {
				((HttpRequestBase) httpUriRequest).setURI(URI.create(httpUriRequest.getURI() + "?" + mEncodedAccessToken));
			} else { 
				((HttpRequestBase) httpUriRequest).setURI(URI.create(httpUriRequest.getURI() +  "&" + mEncodedAccessToken));
			} 
		} 
	} 
	 
	public HttpParams getParams() {
		return mHttpClient.getParams();
	} 
	 
	public ClientConnectionManager getConnectionManager() {

6
CodeRank
This code example shows how to use the following methods:addHeader
This code example shows how to use the following methods:addHeader, getURI
        callMethod(post, operation);
    } 
 
    private void callMethod(HttpUriRequest request, Operation operation) throws IOException {
        // Specify GData protocol version 2.0. 
        request.addHeader("GData-Version", "2");
 
        // Indicate support for gzip-compressed responses. 
        request.addHeader("Accept-Encoding", "gzip");
 
        // Specify authorization token if provided. 
        String authToken = mAuthToken;
        if (!TextUtils.isEmpty(authToken)) {
            request.addHeader("Authorization", "GoogleLogin auth=" + authToken);
        } 
 
        // Specify the ETag of a prior response, if available. 
        String etag = operation.inOutEtag;
        if (etag != null) {
            request.addHeader("If-None-Match", etag);

6
CodeRank
This code example shows how to use the following methods:setHeader
	public void set(HttpUriRequest request) {
 
		if (mUserAgent == null)
			update(null); 
 
		request.setHeader(HEADER_USER_AGENT, mUserAgent);
	} 
 
	/** 
	 * static method to get display params. 
	 *  
	 * @param activity 
	 *            a target Activity class object. 
	 * @return int-array if activity would not null, null if activity would be 
	 *         null. 
	 */ 
	public static int[] getDisplayParams(Activity activity) {
 
		if (activity != null) {
 
6
CodeRank
This code example shows how to use the following methods:abort, isAborted
			try { 
				if(context==null){
					httpResponse = httpClient.execute(request);
				} 
				else{ 
					httpResponse =httpClient.execute(request ,context );
				} 
			} catch (IOException e) {
				ioe = e;
			} 
			 
			//Log.i(TAG,"get httpResponse="+ioe+" request="+request); 
			 
			try{ 
				if(callback!=null)
					callback.callback(request, httpResponse , attachment, ioe);
			}catch (Exception e) {
				Log.e(TAG, e.getMessage(),e);
			}finally{ 
				if(!request.isAborted())

5
CodeRank
This code example shows how to use the following methods:addHeader
 
 
    // Private stuff 
    protected void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, AsyncHttpResponseHandler responseHandler, Context context) {
        if(contentType != null) {
            uriRequest.addHeader("Content-Type", contentType);
        } 
 
        Future<?> request = threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler));
 
        if(context != null) {
            // Add request to request map 
            List<WeakReference<Future<?>>> requestList = requestMap.get(context);
            if(requestList == null) {
                requestList = new LinkedList<WeakReference<Future<?>>>();
                requestMap.put(context, requestList);
            } 
 
            requestList.add(new WeakReference<Future<?>>(request));
 
5
CodeRank
This code example shows how to use the following methods:getAllHeaders, getMethod, getURI
 
    ArgumentCaptor<HttpUriRequest> requestCaptor = ArgumentCaptor.forClass(HttpUriRequest.class);
    verify(mMockHttpClient).execute(requestCaptor.capture());
 
    HttpUriRequest request = requestCaptor.getValue();
    assertEquals("HEAD", request.getMethod());
    assertEquals("https://www.google.com", request.getURI().toString());
    MoreAsserts.assertEmpty(Arrays.asList(request.getAllHeaders()));
  } 
 
  public void testResponseWithValidDate() throws Exception { 
    withHttpRequestReturningDate("Tue, 05 Jun 2012 22:54:01 GMT"); 
    assertEquals(1338936841000L, mProvider.getNetworkTime());
  } 
 
  public void testResponseWithMissingDate() throws Exception { 
    withHttpRequestReturningDate(null); 
    try { 
      mProvider.getNetworkTime();
      fail();
5
CodeRank
This code example shows how to use the following methods:setHeader
		return download(new HttpGet(url), new SizeCountOutputStream(outputStream), 0, 0);
	} 
 
	protected boolean download(HttpUriRequest request, SizeCountOutputStream outputStream, long downloadedBytes, int retry) {
		if (downloadedBytes > 0)
			request.setHeader("Range", "bytes=" + downloadedBytes + "-");
 
		try { 
			return download(request, outputStream);
		} catch (IOException e) {
			if (retry + 1 < RETRY_MAX) {
				return download(request, outputStream, outputStream.getSize(), retry + 1);
			} else { 
				return false; 
			} 
		} 
	} 
 
	protected boolean download(HttpUriRequest request, OutputStream outputStream) throws IOException {
		mStatusLine = null;

5
CodeRank
This code example shows how to use the following methods:
    String url=String.format(format, loc.getLatitude(),
                             loc.getLongitude());
    HttpGet getMethod=new HttpGet(url);
     
    try { 
      ResponseHandler<String> responseHandler=new BasicResponseHandler();
      String responseBody=client.execute(getMethod,
                                         responseHandler);
      buildForecasts(responseBody);
       
      String page=generatePage();
     
      browser.loadDataWithBaseURL(null, page, "text/html",
                                  "UTF-8", null); 
    } 
    catch (Throwable t) {
      android.util.Log.e("WeatherDemo", "Exception fetching data", t);
      Toast 
        .makeText(this, "Request failed: "+t.toString(), Toast.LENGTH_LONG)
        .show();
8
CodeRank

Related Android HttpUriRequest Questions & Answers:

See Code Examples for Android HttpUriRequest Methods: