Skip to content

Instantly share code, notes, and snippets.

@devrath
Created November 19, 2014 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devrath/7b4eb4ec94fa77804ab8 to your computer and use it in GitHub Desktop.
Save devrath/7b4eb4ec94fa77804ab8 to your computer and use it in GitHub Desktop.
SimpleApacheServerRequest to get data
package com.findmybuffet.utilities;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
public class SendHttpRequest {
public static String doConnection(String url) throws ClientProtocolException,IOException,Exception{
/*HttpGet httpget=null;
String mContent=null;
HttpClient Client=null;
Map<String, String> mapResult=new HashMap<String, String>();
Client = new DefaultHttpClient();
httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
mContent = Client.execute(httpget, responseHandler);*/
HttpGet httpget=null;
String mContent=null;
HttpClient Client=null;
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 500);
Client = new DefaultHttpClient(params);
httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
mContent = Client.execute(httpget, responseHandler);
} catch (ClientProtocolException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw e;
}
return mContent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment