List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:de.hybris.platform.integration.cis.payment.strategies.impl.CisPaymentIntegrationTestHelper.java
public static Map<String, String> createNewProfile(final String cybersourceUrl, final List<BasicNameValuePair> formData) throws Exception // NO PMD { final DefaultHttpClient client = new DefaultHttpClient(); final HttpPost postRequest = new HttpPost(cybersourceUrl); postRequest.getParams().setBooleanParameter("http.protocol.handle-redirects", true); postRequest.setEntity(new UrlEncodedFormEntity(formData, "UTF-8")); // Execute HTTP Post Request final HttpResponse response = client.execute(postRequest); final Map<String, String> responseParams = new HashMap<String, String>(); BufferedReader bufferedReader = null; try {//from ww w . ja v a2 s. c o m bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); while (bufferedReader.ready()) { final String currentLine = bufferedReader.readLine(); if (currentLine.contains("value=\"") && currentLine.contains("name=\"")) { final String[] splittedLine = currentLine.split("name=\""); final String key = splittedLine[1].split("value=\"")[0].replace("\"", "").replace(">", "") .trim(); final String value = splittedLine[1].split("value=\"")[1].replace("\"", "").replace(">", "") .trim(); responseParams.put(key, value); } } } finally { IOUtils.closeQuietly(bufferedReader); } return responseParams; }
From source file:Main.java
/** * Op Http post request , "404error" response if failed * //from w ww.j a v a2 s.c o m * @param url * @param map * Values to request * @return */ static public String doHttpPost(String url, HashMap<String, String> map) { HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT); HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT); ConnManagerParams.setTimeout(client.getParams(), TIMEOUT); HttpPost post = new HttpPost(url); post.setHeaders(headers); String result = "ERROR"; ArrayList<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>(); if (map != null) { for (Map.Entry<String, String> entry : map.entrySet()) { BasicNameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue()); pairList.add(pair); } } try { HttpEntity entity = new UrlEncodedFormEntity(pairList, "UTF-8"); post.setEntity(entity); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { result = EntityUtils.toString(response.getEntity(), "UTF-8"); } else { result = EntityUtils.toString(response.getEntity(), "UTF-8") + response.getStatusLine().getStatusCode() + "ERROR"; } } catch (ConnectTimeoutException e) { result = "TIMEOUTERROR"; } catch (Exception e) { result = "OTHERERROR"; e.printStackTrace(); } return result; }
From source file:org.mustard.util.MustardUtil.java
public static void snapshot(String id, String version, String accountNumber) { try {/* w ww . j ava 2s . c om*/ HttpPost post = new HttpPost("http://mustard.macno.org/snapshot.php"); ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("v", version)); params.add(new BasicNameValuePair("n", accountNumber)); params.add(new BasicNameValuePair("m", id)); post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); DefaultHttpClient hc = new DefaultHttpClient(); HttpProtocolParams.setUserAgent(post.getParams(), "Mustard/1.0"); HttpProtocolParams.setUseExpectContinue(post.getParams(), false); hc.execute(post); } catch (Exception e) { } }
From source file:org.opf_labs.fmts.fidget.droid.PRONOMSigGenerator.java
/** * @param sigdef/*from w ww .j a va 2 s .co m*/ */ 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:org.opencastproject.util.HttpUtil.java
private static void setFormParams(HttpEntityEnclosingRequest r, NameValuePair[] formParams) { final List<NameValuePair> params = list(formParams); try {/*from w w w .ja v a2s . c om*/ r.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); } catch (UnsupportedEncodingException e) { chuck(e); } }
From source file:pj.rozkladWKD.HttpClient.java
public static JSONObject SendHttpPost(List<NameValuePair> nameValuePairs) throws JSONException, ClientProtocolException, IOException { // Create a new HttpClient and Post Header DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.mmaj.nazwa.pl/rozkladwkd/listener2.php"); nameValuePairs.add(new BasicNameValuePair("app_ver", RozkladWKD.APP_VERSION)); // Add your data httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF_8")); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { // Read the content stream InputStream instream = entity.getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); }//from w ww . j ava 2 s .c om // convert content stream to a String String resultString = convertStreamToString(instream); instream.close(); //resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]" // Transform the String into a JSONObject if (RozkladWKD.DEBUG_LOG) { Log.i(TAG, "result: " + resultString); } JSONObject jsonObjRecv = new JSONObject(resultString); // Raw DEBUG output of our received JSON object: if (RozkladWKD.DEBUG_LOG) { Log.i(TAG, "<jsonobject>\n" + jsonObjRecv.toString() + "\n</jsonobject>"); } return jsonObjRecv; } return null; }
From source file:com.android.isoma.enc.ServerCommunicator.java
public static String executePost(ArrayList<NameValuePair> postParameters) { String ServerResponse = null; HttpClient httpClient = getHttpClient(); ResponseHandler<String> response = new BasicResponseHandler(); HttpPost request = new HttpPost(url); try {/*from w w w .j ava 2s . co m*/ request.setHeader("Content-Type", "application/x-www-form-urlencoded"); request.setEntity(new UrlEncodedFormEntity(postParameters, HTTP.UTF_8)); ServerResponse = httpClient.execute(request, response); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ServerResponse; }
From source file:cn.comgroup.tzmedia.server.util.mail.SendCloudMail.java
/** * Send email using SMTP server./*from ww w . ja v a2 s. co m*/ * * @param recipientEmail TO recipient * @param title title of the message * @param message message to be sent * connected state or if the message is not a MimeMessage */ public static void send(String recipientEmail, String title, String message) throws UnsupportedEncodingException, IOException { String url = "http://sendcloud.sohu.com/webapi/mail.send.json"; HttpClient httpclient = new DefaultHttpClient(); HttpPost httpost = new HttpPost(url); List nvps = new ArrayList(); // ??SendCloud????????????????? nvps.add(new BasicNameValuePair("api_user", "commobile_test_IxiZE1")); nvps.add(new BasicNameValuePair("api_key", "0tkHZ5vDdScYzRbn")); nvps.add(new BasicNameValuePair("from", "suport@tzzjmedia.net")); nvps.add(new BasicNameValuePair("to", recipientEmail)); nvps.add(new BasicNameValuePair("subject", title)); nvps.add(new BasicNameValuePair("html", message)); httpost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8")); // HttpResponse response = httpclient.execute(httpost); // ?? if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // // ?xml String result = EntityUtils.toString(response.getEntity()); Logger.getLogger(SendCloudMail.class.getName()).log(Level.INFO, result); } else { System.err.println("error"); } }
From source file:pingdesktop.Model.HttpHandler.java
public static String doPost(List<NameValuePair> nvps, String target_url) throws IOException { /* create the HTTP client and POST request */ HttpPost httpPost = new HttpPost(BaseUrl + target_url); /* add some request parameters for a form request */ // List<NameValuePair> nvps = new ArrayList<NameValuePair>(); ////from ww w .j av a 2 s.co m // nvps.add(new BasicNameValuePair("username", "pangeranweb")); // nvps.add(new BasicNameValuePair("password", "anisnuzulan")); nvps.add(new BasicNameValuePair("Content-Type", "application/x-www-form-urlencoded")); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); /* execute request */ HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); /* process response */ if (httpResponse.getStatusLine().getStatusCode() == 200) { String responseText = EntityUtils.toString(httpEntity); return responseText; } else { return "Invalid HTTP response: " + httpResponse.getStatusLine().getStatusCode(); } }
From source file:no.hig.gsd.quizgame.ServerUtilities.java
/** * Register this account/device pair within the server. * * @return whether the registration succeeded or not. *//*from w w w.j av a 2s . c o m*/ public static String register(final Context context, final String regId) { Log.i("remote", "registering device (regId = " + regId + ")"); String usm = LoginActivity.usm; String retSrc = ""; try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://89.250.116.142/Quizgame/jaxrs/quizgame/gcm"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("username", usm)); nameValuePairs.add(new BasicNameValuePair("regId", regId)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); HttpResponse httpResponse = client.execute(post); HttpEntity entity = httpResponse.getEntity(); retSrc = EntityUtils.toString(entity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (retSrc.equals("success")) { return status = "success"; } else { return status = "failure"; } }