Created
November 19, 2014 09:51
-
-
Save devrath/7b4eb4ec94fa77804ab8 to your computer and use it in GitHub Desktop.
SimpleApacheServerRequest to get data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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