Android HttpRequestBase - 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 HttpRequestBase class.

This code example shows how to use the following methods:setEntity, abort, setHeader
		} 
	} 
 
	protected void postMethod(StreamData data, String url, String body) throws ArtAroundException {
		final AndroidHttpClient client = getNewHttpClient();
		final HttpPost postRequest = new HttpPost(url);
		try { 
			HttpEntity entity = new StringEntity(body);
			postRequest.setEntity(entity);
			postRequest.setHeader("Accept", "application/json");
			postRequest.setHeader("Content-Type", "application/json");
 
			HttpResponse response = client.execute(postRequest);
			parseHttpResponse(data, url, response);
		} 
		catch (IOException e) {
			throw new ArtAroundException(e);
		} 
		finally { 
			if (postRequest != null) {

7
CodeRank
This code example shows how to use the following methods:abort, isAborted
     * stop request task. 
     */ 
    @Override 
    public void stop() { 
        this.mStop = true;
        if (request != null && !request.isAborted()) {
            request.abort();
        } 
        if (!this.isCancelled()) {
            this.cancel(true);
        } 
    } 
 
    public boolean isStop() { 
        return mStop;
    } 
 
    private long lastUpdateTime;
 
    @Override 
6
CodeRank
This code example shows how to use the following methods:abort, getURI
public class ClientAbortMethod { 
 
    public final static void main(String[] args) throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        try { 
            HttpGet httpget = new HttpGet("http://www.apache.org/");
 
            System.out.println("executing request " + httpget.getURI());
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
 
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
            } 
            System.out.println("----------------------------------------");
 
            // Do not feel like reading the response body 
            // Call abort on the request object 

6
CodeRank
This code example shows how to use the following methods:abort, getURI
public class ClientConnectionRelease { 
 
    public final static void main(String[] args) throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        try { 
            HttpGet httpget = new HttpGet("http://www.apache.org/");
 
            // Execute HTTP request 
            System.out.println("executing request " + httpget.getURI());
            HttpResponse response = httpclient.execute(httpget);
 
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            System.out.println("----------------------------------------");
 
            // Get hold of the response entity 
            HttpEntity entity = response.getEntity();
 
            // If the response does not enclose an entity, there is no need 
            // to bother about connection release 

6
CodeRank
This code example shows how to use the following methods:abort
 
  @Override 
  protected  DailyResponse doInBackground(Object... is) {
    HttpClient httpclient = new DefaultHttpClient();
    String url = Util.getHarvestBase(context) + "/daily";
    HttpRequestBase requestBase = new HttpGet(url);
    Util.addBasicAuthAndHarvestHeaders(context, requestBase);
    try { 
      HttpResponse httpResponse = httpclient.execute(requestBase);
      String content = Util.getContentFromHttpResponse(httpResponse);
      DailyResponse dailyResponse = Util.getGson().fromJson(content, DailyResponse.class);
      return dailyResponse;
    } catch (Exception e) {
      requestBase.abort();
      Log.e(TAG, e.getMessage(), e);
    } 
    return null; 
  } 
   
  @Override 
6
CodeRank
This code example shows how to use the following methods:getURI
public class ClientWithResponseHandler { 
	 public final static void main(String[] args) throws Exception {
	         
	        HttpClient httpclient = new DefaultHttpClient();
 
	        HttpGet httpget = new HttpGet("http://www.google.com/"); 
 
	        System.out.println("executing request " + httpget.getURI());
 
	        // Create a response handler 
	        ResponseHandler<String> responseHandler = new BasicResponseHandler();
	        String responseBody = httpclient.execute(httpget, responseHandler);
	        System.out.println(responseBody);
	         
	        System.out.println("----------------------------------------");
 
	        // When HttpClient instance is no longer needed,  
	        // shut down the connection manager to ensure 
	        // immediate deallocation of all system resources 
	        httpclient.getConnectionManager().shutdown();        
6
CodeRank
This code example shows how to use the following methods:setHeader, addHeader, setHeader,
		} 
	} 
 
	private void composeHeader(HttpRequestBase httpRequest) {		
 
		httpRequest.setHeader("x-amz-sns-message-type", this.getMessageType());
		httpRequest.setHeader("x-amz-sns-message-id", this.getMessageId());
		httpRequest.setHeader("x-amz-sns-topic-arn", this.getTopicArn());
		httpRequest.setHeader("x-amz-sns-subscription-arn", this.getSubscriptionArn());
		httpRequest.setHeader("User-Agent", "Cloud Notification Service Agent");
 
		if (this.getRawMessageDelivery()) {
			httpRequest.addHeader("x-amz-raw-message", "true");
		} 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setEntity, setURI, setHeader
     */ 
    @Override 
    public void sendPasosMessage(PasosMessage message) throws URISyntaxException,
            ClientProtocolException, IOException { 
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost();
        post.setHeader("sender-mobile-number", this.senderNumber);
        URI uri = new URI(this.url);
        post.setURI(uri);
        post.setEntity(new StringEntity(message.toString()));
        client.execute(post);
    } 
 
    @Override 
    public void sendPasosMessage(String message) throws URISyntaxException,
            ClientProtocolException, IOException { 
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost();
        post.setHeader("sender-mobile-number", this.senderNumber);
        URI uri = new URI(this.url);
6
CodeRank
This code example shows how to use the following methods:setURI, getParams, setParams
This code example shows how to use the following methods:abort
 
	public void abort() { 
		try { 
			if (httpClient != null) {
				Log.i(TAG, "Abort.");
				httpPost.abort();
			} 
		} catch (Throwable e) {
			Log.e(TAG, "Failed to abort", e);
		} 
	} 
 
	public String sendPost(String url, Map<String, String> params) {
		return sendPost(url, params, null);
	} 
 
	public String sendPost(String url, Map<String, String> params,
			String contentType) {
		ret = null;
 
6
CodeRank

Related Android HttpRequestBase Questions & Answers:

See Code Examples for Android HttpRequestBase Methods: