List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters)
From source file:bit.changepurse.wdk.util.CheckedExceptionMethods.java
public static HttpEntity newHttpEntity(List<? extends NameValuePair> params) { try {//from w w w.ja va 2 s . c o m return new UrlEncodedFormEntity(params); } catch (UnsupportedEncodingException e) { throw new UncheckedException(e); } }
From source file:com.swetha.easypark.EasyParkHttpClient.java
/** * @param url of the website and the post request * @return http response in string */ public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception { BufferedReader in = null;/* w w w . j a v a2 s .c om*/ try { HttpClient client = getHttpClient(); HttpPost request = new HttpPost(url); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity( postParameters); request.setEntity(formEntity); Log.i("CustomHttpClient", "before sending request" + request); HttpResponse response = client.execute(request); Log.i("CustomHttpClient", "after sending request" + response.toString()); //Log.i("CustomHttpClient", "after sending request response in to string" +response.getEntity().getContent().toString()); in = new BufferedReader(new InputStreamReader(response.getEntity() .getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String result = sb.toString(); return result; } finally { if (in != null) { try { in.close(); } catch (IOException e) { Log.e("log_tag", "Error converting result " + e.toString()); e.printStackTrace(); } } } }
From source file:org.opencastproject.remotetest.server.resource.IngestResources.java
/** * //from ww w . j a va 2 s . c o m * @param type * Type of media to add: Track, Catalog, Attachment * */ public static HttpResponse add(TrustedHttpClient client, String type, String url, String flavor, String mediaPackage) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "add" + type); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("url", url)); params.add(new BasicNameValuePair("flavor", flavor)); params.add(new BasicNameValuePair("mediaPackage", mediaPackage)); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }
From source file:br.com.estudogrupo.online.DicionarioOnline02.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.md5pass.info"); try {/* ww w . ja v a2s . co m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("hash", getRecebe())); nameValuePairs.add(new BasicNameValuePair("get_pass", "Get+Pass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { if (line.startsWith("Password -")) { System.out.println("Senha : " + line.replace("<b>", "").replace("</b>", "").replace("-", "").replace("Password", "")); System.exit(0); } } } catch (IOException | NullPointerException e) { e.printStackTrace(); } }
From source file:com.dnastack.bob.service.processor.util.HttpUtils.java
private static HttpPost createPost(String url, List<NameValuePair> data) throws UnsupportedEncodingException { HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(data)); return httpPost; }
From source file:com.yattatech.gcm.format.PlainTextFormat.java
@Override public HttpEntity getRequest(String registrationId, String message) throws Exception { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId)); nameValuePairs.add(new BasicNameValuePair("delay_while_idle", "true")); nameValuePairs.add(new BasicNameValuePair("data.message", message)); nameValuePairs.add(new BasicNameValuePair("data.time", String.valueOf(System.currentTimeMillis()))); nameValuePairs.add(new BasicNameValuePair("data.agent", "GCMSenderTest")); return new UrlEncodedFormEntity(nameValuePairs); }
From source file:att.jaxrs.client.Webinar.java
public static String addWebinar(Webinar webinar) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", webinar.getContent_id().toString())); urlParameters.add(new BasicNameValuePair("presenter", webinar.getPresenter())); String resultStr = ""; try {/*from w ww . j a v a2 s .c om*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_WEBINAR_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:br.com.estudogrupo.online.DicionarioOnline03.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.cloudcracker.net/index.php"); try {/*w w w.ja va 2s. c o m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("inputbox", getRecebe())); nameValuePairs.add(new BasicNameValuePair("submit", "Crack+MD5+Hash")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine().trim()) != null) { if (line.startsWith("Word:")) { String key = line.substring(96); System.out.println("Senha : " + key.replace("\"", "").replace("/>", "")); System.exit(0); } } } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { } }
From source file:aop.controller.RequestController.java
public void sendPostReq(int id, String type) throws Exception { boolean debug = false; String url = "http://localhost:1337/"; CloseableHttpClient httpClient = HttpClients.createDefault(); try {/*from w ww.j a v a 2 s. c o m*/ HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("id", Integer.toString(id))); urlParameters.add(new BasicNameValuePair("type", type)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = httpClient.execute(post); if (debug) { System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + post.getEntity()); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } System.out.println(result.toString()); } } finally { httpClient.close(); } }
From source file:windsekirun.qrreader.util.JsonReceiver.java
public String makeJsonCall(String url, int method, List<NameValuePair> params) { try {//from w ww .j av a 2 s . co m DefaultHttpClient httpClient = new DefaultHttpClient(); HttpEntity httpEntity; HttpResponse httpResponse = null; if (method == POST) { HttpPost httpPost = new HttpPost(url); if (params != null) httpPost.setEntity(new UrlEncodedFormEntity(params)); httpResponse = httpClient.execute(httpPost); } else if (method == GET) { if (params != null) { String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; } HttpGet httpGet = new HttpGet(url); httpResponse = httpClient.execute(httpGet); } assert httpResponse != null; httpEntity = httpResponse.getEntity(); response = EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return response; }