3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
8 import org.apache.http.HttpEntity;
9 import org.apache.http.HttpResponse;
10 import org.apache.http.NameValuePair;
11 import org.apache.http.client.ClientProtocolException;
12 import org.apache.http.client.HttpClient;
13 import org.apache.http.client.entity.UrlEncodedFormEntity;
14 import org.apache.http.client.methods.HttpPost;
15 import org.apache.http.impl.client.DefaultHttpClient;
18 * Helpful procedures for working with services via HTTPClient
22 public class HttpClientUtils
25 * do a minimal HTTP post with URL-Encoded parameters passed in the Query
30 * @return Reader containing content, if any, or null if no entity returned.
32 * @throws ClientProtocolException
35 public static BufferedReader doHttpUrlPost(String postUrl,
36 List<NameValuePair> vals) throws ClientProtocolException,
39 HttpClient httpclient = new DefaultHttpClient();
40 HttpPost httppost = new HttpPost(postUrl);
41 UrlEncodedFormEntity ue = new UrlEncodedFormEntity(vals, "UTF-8");
42 httppost.setEntity(ue);
43 HttpResponse response = httpclient.execute(httppost);
44 HttpEntity resEntity = response.getEntity();
46 if (resEntity != null)
48 BufferedReader r = new BufferedReader(new InputStreamReader(
49 resEntity.getContent()));