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:com.squeezeday.marknadskoll.HttpHelper.java
public static String post(String url, List<? extends NameValuePair> parameters) throws IOException, HttpException { HttpPost request = new HttpPost(url); request.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8)); return doRequest(request, url, new BasicHttpContext(), true); }
From source file:org.ow2.bonita.facade.rest.apachehttpclient.ApacheHttpClientUtil.java
public static HttpResponse executeHttpConnection(String uri, List<NameValuePair> formParams, String options, String username, String password) throws URISyntaxException, IOException, IOException { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8"); String serverAddress = HttpRESTUtil.getRESTServerAddress(); HttpPost post = new HttpPost(serverAddress + uri); post.setEntity(entity);//from w ww. j a v a 2 s. c o m HttpClient client = ApacheHttpClientUtil.getHttpClient(serverAddress, username, password); HttpResponse httpresponse = client.execute(post); return httpresponse; }
From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java
private static Response doPost(String url, List<NameValuePair> postdata) { HttpClient httpclient = getHttpClient(); try {/*from w w w .ja v a2s . 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.e2.MessageSender.java
public static void send(String text) { Map<String, String> json = new HashMap<String, String>(); int second = Integer.parseInt(String.valueOf(System.currentTimeMillis()).substring(9, 10)); try {/*w w w .j a va 2s . com*/ String url = "http://taku.st-sweet.com:8082/e_000/hosts"; HttpClient client = HttpClientBuilder.create().build(); HttpPost httpPost = new HttpPost(url); //Create Message Object json.put("mmCall", "1"); json.put("mType", "5"); json.put("id", "tw_" + String.valueOf(System.currentTimeMillis())); json.put("x", "50"); json.put("y", second % 2 == 0 ? "5" : "95"); json.put("appearFade", "true"); json.put("appearSlide", "2"); json.put("appearSize", "1"); json.put("disappearFade", "true"); json.put("disappearSlide", "3"); json.put("disappearSize", "2"); json.put("liveTime", "150"); json.put("rectColor", colorPattern[second / 2]); json.put("text", text); json.put("textColor", "#DDD"); json.put("textAlign", "2"); List<NameValuePair> nvps = new ArrayList<>(); for (Iterator it = json.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry<String, String>) it.next(); nvps.add(new BasicNameValuePair(entry.getKey().toString(), entry.getValue().toString())); } // System.out.println(new UrlEncodedFormEntity(nvps).toString()); httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8")); client.execute(httpPost); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.cappuccino.requestframework.PostRequestHelper.java
public HttpEntity getHttpEntity() { // ? ?/* w ww. j a v a 2s . com*/ ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); for (RequestParam param : params) { nameValuePairs.add(new BasicNameValuePair(param.getSsKey(), param.getValue())); } // HttpEtity ? HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(nameValuePairs, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return entity; }
From source file:driimerfinance.helpers.FinanceHelper.java
/** * Checks if the license is valid using the License Key Server * * @param license key to check// w w w. ja v a 2 s .com * @return validity of the license (true or false) */ public static boolean checkLicense(String licenseKey) { HttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost("http://driimerfinance.michaelkohler.info/checkLicense"); List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("key", licenseKey)); // pass the key to the server try { httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); } catch (UnsupportedEncodingException e) { return false; } HttpResponse response = null; try { response = httpclient.execute(httppost); // get the response from the server } catch (IOException e) { return false; } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); @SuppressWarnings("resource") java.util.Scanner s = new java.util.Scanner(instream).useDelimiter("\\A"); // parse the response String responseString = s.hasNext() ? s.next() : ""; instream.close(); return responseString.contains("\"valid\":true"); // if the license is valid, return true, else false } catch (IllegalStateException | IOException e) { return false; } } return false; }
From source file:com.abombrecords.amt_unlocker.AMT_Unlocker.java
public static boolean UnlockDoor(String Username, String Password, String DoorPIN) throws Exception { boolean bSuccess = false; //Log.d(LogTag, "Login"); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpost = new HttpPost("http://acemonstertoys.org/node?destination=node"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("op", "Log in")); nvps.add(new BasicNameValuePair("name", Username)); nvps.add(new BasicNameValuePair("pass", Password)); nvps.add(new BasicNameValuePair("openid.return_to", "http://acemonstertoys.org/openid/authenticate?destination=node")); nvps.add(new BasicNameValuePair("form_id", "user_login_block")); nvps.add(new BasicNameValuePair("form_build_id", "form-4d6478bc67a79eda5e36c01499ba4c88")); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); //Log.d(LogTag, "Login form get: " + response.getStatusLine()); if (entity != null) { entity.consumeContent();//from w w w. j av a 2s. c o m } //Log.d(LogTag, "Post Login cookies:"); // look for drupal_uid and fail out if it isn't there List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { //Log.d(LogTag, "None"); } else { for (int i = 0; i < cookies.size(); i++) { //Log.d(LogTag, "- " + cookies.get(i).toString()); if (cookies.get(i).getName().equals("drupal_uid")) { bSuccess = true; } } } if (bSuccess) { HttpPost httpost2 = new HttpPost("http://acemonstertoys.org/membership"); List<NameValuePair> nvps2 = new ArrayList<NameValuePair>(); nvps2.add(new BasicNameValuePair("doorcode", DoorPIN)); nvps2.add(new BasicNameValuePair("forceit", "Open Door")); httpost2.setEntity(new UrlEncodedFormEntity(nvps2, HTTP.UTF_8)); response = httpclient.execute(httpost2); entity = response.getEntity(); //Log.d(LogTag, "Unlock form get: " + response.getStatusLine()); if (entity != null) { entity.consumeContent(); } } httpclient.getConnectionManager().shutdown(); return bSuccess; }
From source file:net.bither.api.BitherErrorApi.java
@Override public HttpEntity getHttpEntity() throws Exception { List<NameValuePair> params = new ArrayList<NameValuePair>(); if (!Utils.isEmpty(this.mErrorMsg)) { params.add(new BasicNameValuePair(ERROR_MSG, this.mErrorMsg.trim())); }//ww w . j av a2 s.co m return new UrlEncodedFormEntity(params, HTTP.UTF_8); }
From source file:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTideAreaButtonClickHttpPost.java
public EasyTideAreaButtonClickHttpPost(URI uri, String viewState, String eventValidation) { super(uri, viewState); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__VIEWSTATE", viewState)); nvps.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation)); //nvps.add(new BasicNameValuePair("__EVENTTARGET", "")); //nvps.add(new BasicNameValuePair("__EVENTARGUMENT", "")); nvps.add(new BasicNameValuePair("imgSelectAreas.x", "38")); nvps.add(new BasicNameValuePair("imgSelectAreas.y", "19")); setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); }
From source file:LogToFile.java
private static HttpPost Post(String url, HashMap<String, String> params, HashMap<String, ArrayList<String>> arrayParams) { try {/* w w w .j a va 2 s.co m*/ if (!url.endsWith("/")) url += "/"; List<NameValuePair> params_list = null; if (params != null) { params_list = new LinkedList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } if (arrayParams != null) { if (params_list == null) params_list = new LinkedList<NameValuePair>(); for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet()) for (String value : entry.getValue()) params_list.add(new BasicNameValuePair(entry.getKey(), value)); } HttpPost request = new HttpPost(url); if (params != null) request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8")); return request; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }