2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import java.io.BufferedReader;
21 import java.io.IOException;
22 import java.io.InputStreamReader;
23 import java.util.List;
25 import org.apache.http.HttpEntity;
26 import org.apache.http.HttpResponse;
27 import org.apache.http.NameValuePair;
28 import org.apache.http.client.ClientProtocolException;
29 import org.apache.http.client.HttpClient;
30 import org.apache.http.client.entity.UrlEncodedFormEntity;
31 import org.apache.http.client.methods.HttpPost;
32 import org.apache.http.impl.client.DefaultHttpClient;
35 * Helpful procedures for working with services via HTTPClient
39 public class HttpClientUtils
42 * do a minimal HTTP post with URL-Encoded parameters passed in the Query
47 * @return Reader containing content, if any, or null if no entity returned.
49 * @throws ClientProtocolException
52 public static BufferedReader doHttpUrlPost(String postUrl,
53 List<NameValuePair> vals) throws ClientProtocolException,
56 HttpClient httpclient = new DefaultHttpClient();
57 HttpPost httppost = new HttpPost(postUrl);
58 UrlEncodedFormEntity ue = new UrlEncodedFormEntity(vals, "UTF-8");
59 httppost.setEntity(ue);
60 HttpResponse response = httpclient.execute(httppost);
61 HttpEntity resEntity = response.getEntity();
63 if (resEntity != null)
65 BufferedReader r = new BufferedReader(new InputStreamReader(
66 resEntity.getContent()));