Android Open Source - habhub-chase-car-tracker Simple Http






From Project

Back to project page habhub-chase-car-tracker.

License

The source code is released under:

Copyright (c) 2012, Priyesh Patel All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1...

If you think the Android project habhub-chase-car-tracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.pexat.net;
//w  w w  .  ja va2 s  . c  o  m
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.DefaultHttpClient;

public class SimpleHttp {

  public static String get(String url) {
    BufferedReader reader = null;
    String page = "";

    try {
      HttpClient client = new DefaultHttpClient();
      HttpGet request = new HttpGet();

      request.setURI(new URI(url));

      HttpResponse response = client.execute(request);

      reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

      StringBuffer buffer = new StringBuffer("");
      String line = "";
      String newline = System.getProperty("line.separator");

      while ((line = reader.readLine()) != null) {
        buffer.append(line + newline);
      }

      reader.close();

      page = buffer.toString();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    return page;
  }

  public static void post(String url, HttpEntity data) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpost = new HttpPost(url);

    try {
      httpost.setEntity(data);
      httpclient.execute(httpost);
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static void put(String url, HttpEntity data) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPut httpput = new HttpPut(url);

    try {
      httpput.setEntity(data);
      httpclient.execute(httpput);
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}




Java Source Code List

com.pexat.habhub.chasecartracker.About.java
com.pexat.habhub.chasecartracker.AppInfo.java
com.pexat.habhub.chasecartracker.HabitatInterface.java
com.pexat.habhub.chasecartracker.ListenerTelemetry.java
com.pexat.habhub.chasecartracker.Main.java
com.pexat.habhub.chasecartracker.TrackerService.java
com.pexat.net.SimpleHttp.java