Android Open Source - semana-isw2013 Http Helper






From Project

Back to project page semana-isw2013.

License

The source code is released under:

Apache License

If you think the Android project semana-isw2013 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 mobi.itson.semanaisw2013app.utils;
//from  w ww.  j av a2  s .c o  m
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpHelper {

  public String DoPost(String url, List<NameValuePair> params) throws IOException{
    //Create a new httpclient and post header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new UrlEncodedFormEntity(params));
    //Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httpPost);
    String result = convertStreamToString(response.getEntity().getContent());
    
    return result;
  }
  
  public String DoGet(String url, List<NameValuePair> params) throws IOException{
    //create a new HttpClient and get Header
    HttpClient httpClient = new DefaultHttpClient();
    if(params!=null){
      url.concat("?").concat(URLEncodedUtils.format(params, "UTF-8"));
    }
    HttpGet httpGet = new HttpGet(url);
    //Execute HTTP Post Request
    HttpResponse response = httpClient.execute(httpGet);
    String result = convertStreamToString(response.getEntity().getContent());
    
    return result;
  }
  
  private static String convertStreamToString(InputStream inputStream){
    java.util.Scanner scanner = new java.util.Scanner(inputStream).useDelimiter("\\A");
    return scanner.hasNext() ? scanner.next() : "";
  }
}




Java Source Code List

mobi.itson.semanaisw2013app.AboutUsActivity.java
mobi.itson.semanaisw2013app.ConferenceActivity.java
mobi.itson.semanaisw2013app.Conference.java
mobi.itson.semanaisw2013app.ConferencesPagerFragment.java
mobi.itson.semanaisw2013app.GalleryActivity.java
mobi.itson.semanaisw2013app.ImagePagerActivity.java
mobi.itson.semanaisw2013app.MainActivity.java
mobi.itson.semanaisw2013app.ScheduleActivity.java
mobi.itson.semanaisw2013app.SplashActivity.java
mobi.itson.semanaisw2013app.WebView_Register_Actvity.java
mobi.itson.semanaisw2013app.WorkshopActivity.java
mobi.itson.semanaisw2013app.WorkshopPagerFragment.java
mobi.itson.semanaisw2013app.Workshop.java
mobi.itson.semanaisw2013app.utils.ActivityUtils.java
mobi.itson.semanaisw2013app.utils.BitmapHack.java
mobi.itson.semanaisw2013app.utils.Constants.java
mobi.itson.semanaisw2013app.utils.HttpHelper.java
mobi.itson.semanaisw2013app.utils.SemanaUpload.java
mobi.itson.semanaisw2013app.utils.TouchHighlightImageButton.java
mobi.itson.semanaisw2013app.utils.UploadImage.java