List of usage examples for org.apache.http.client.methods HttpPost setEntity
public void setEntity(final HttpEntity entity)
From source file:org.n52.shetland.util.HTTP.java
public static void post(URI uri, byte[] bytes, OutputStream out) throws IOException { HttpPost request = new HttpPost(uri); request.setEntity(new ByteArrayEntity(bytes)); execute(request, out);/*from w w w . j av a 2s .c o m*/ }
From source file:language_engine.HttpUtils.java
public static String doHttpPost(String url, List<NameValuePair> params) { try {// w w w . ja v a2s . com HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse resp = httpClient.execute(httpPost); return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.opf_labs.fmts.fidget.droid.PRONOMSigGenerator.java
/** * @param sigdef//w ww . java2 s . c om */ public static void generatePRONOMSigFile(SigDefSubmission sigdef) { DefaultHttpClient httpclient = new DefaultHttpClient(); try { HttpPost httpost = new HttpPost(SERVICE_URL); httpost.setEntity(new UrlEncodedFormEntity(createNameValuePairs(sigdef), Consts.UTF_8)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); // Print out: IOUtils.copy(entity.getContent(), System.out); // Finish up: EntityUtils.consume(entity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.twitter.hbc.core.HttpConstants.java
public static HttpUriRequest constructRequest(String host, Endpoint endpoint, Authentication auth) { String url = host + endpoint.getURI(); if (endpoint.getHttpMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) { HttpGet get = new HttpGet(url); if (auth != null) auth.signRequest(get, null); return get; } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME)) { HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET)); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); if (auth != null) auth.signRequest(post, endpoint.getPostParamString()); return post; } else {//from www. ja v a 2 s. c om throw new IllegalArgumentException("Bad http method: " + endpoint.getHttpMethod()); } }
From source file:org.openvoters.android.tasks.RemoteAPIVoteTask.java
public static HttpResponse makeRequest(String path, Item item, String uniqueID) throws Exception { JSONObject holder = new JSONObject(); holder.put("candidate", item.getID()); holder.put("ID", uniqueID); int TIMEOUT_MILLISEC = 10000; HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC); HttpClient client = new DefaultHttpClient(httpParams); HttpPost request = new HttpPost(path); request.setEntity(new ByteArrayEntity(holder.toString().getBytes("UTF8"))); HttpResponse response = client.execute(request); return response; }
From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java
private static Response doPost(String url, List<NameValuePair> postdata) { HttpClient httpclient = getHttpClient(); try {// w w w. j a v a 2s . co m HttpPost httpost = new HttpPost(url); httpost.setEntity(new UrlEncodedFormEntity(postdata, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpost); if (response.getStatusLine().getStatusCode() == 200) { ResponseHandler<String> responseHandler = new BasicResponseHandler(); return new Response(responseHandler.handleResponse(response)); } else { return new Response(R.string.ERR_PROV_NO_RESP); } } catch (Exception e) { return new Response(R.string.ERR_CONN_ERR); } finally { // Release the resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.waku.common.http.MyHttpClient.java
public static Document getAsDom4jDoc(String url, MultipartEntity reqEntity) { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler()); try {/*from w w w . jav a 2 s .c o m*/ HttpPost httpPost = new HttpPost(url); httpPost.setEntity(reqEntity); return getResponseAndConvertToDom(httpclient, httpPost); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:de.avanux.android.livetracker2.HttpUtil.java
public static String post(String url, Map<String, String> httpParameters) throws ClientProtocolException, IOException { Log.d(TAG, "HTTP POST " + url); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(httpParameters.size()); Set<String> httpParameterKeys = httpParameters.keySet(); for (String httpParameterKey : httpParameterKeys) { nameValuePairs.add(new BasicNameValuePair(httpParameterKey, httpParameters.get(httpParameterKey))); }// w w w. j a v a 2s . co m HttpPost method = new HttpPost(url); method.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = executeMethod(method); return getResponseAsString(response); }
From source file:com.appassit.http.ApiRequestFactory.java
/** * ?Market API HttpReqeust/*ww w. j a va 2 s . c o m*/ */ public static HttpUriRequest getRequest(String url, RequestMethod requestMethod, ArrayList<BasicNameValuePair> cv) throws IOException { if (requestMethod == RequestMethod.GET) { String finalUrl = getGetRequestUrl(url, cv); HttpGet httpGet = new HttpGet(finalUrl); return httpGet; } else if (requestMethod == RequestMethod.POST) { HttpEntity entity = getPostRequestEntity(cv); HttpPost request = new HttpPost(url); request.setEntity(entity); return request; } else { return null; } }
From source file:com.zhaosen.util.HttpClientUtil.java
License:asdf
@SuppressWarnings({ "rawtypes", "unchecked" }) public static String httpPost(String url, String param) throws ClientProtocolException, IOException { new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); ArrayList params = new ArrayList(); params.add(new BasicNameValuePair("data", param)); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = (new DefaultHttpClient()).execute(httpPost); if (response.getStatusLine().getStatusCode() == 200) { String result = EntityUtils.toString(response.getEntity()); return result; } else {/* w w w . j a v a 2 s . c o m*/ return ""; } }