List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters)
From source file:br.com.estudogrupo.online.DicionarioOnline01.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://md5.my-addr.com/md5_decrypt-md5_cracker_online/md5_decoder_tool.php"); try {/* w ww .ja v a 2s. co m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("md5", getRecebe())); 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( "<div class='white_bg_title'><span class='middle_title'>Hashed string</span>")) { String key = line.substring(77).replaceAll("</div>", ""); System.out.println("Senha : " + key); System.exit(0); } } } catch (IOException | NullPointerException e) { e.printStackTrace(); } }
From source file:uk.codingbadgers.SurvivalPlus.error.ReportExceptionRunnable.java
public boolean run() { try {//w ww . j a va2 s. c om List<NameValuePair> data = new ArrayList<NameValuePair>(); data.add(new BasicNameValuePair("password", DigestUtils.md5Hex(SurvivalPlus.getConfigurationManager().getCrashPassword()))); data.add(new BasicNameValuePair("project", "bFundamentals")); data.add(new BasicNameValuePair("cause", getException(throwable))); data.add(new BasicNameValuePair("message", getMessage(throwable))); data.add(new BasicNameValuePair("st", buildStackTrace(throwable))); HttpPost post = new HttpPost("http://server.mcbadgercraft.com/crash/report.php"); post.setEntity(new UrlEncodedFormEntity(data)); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse responce = client.execute(post); String result = EntityUtils.toString(responce.getEntity()); if (SurvivalPlus.getConfigurationManager().isDebugEnabled()) System.out.println(result); JSONObject object = (JSONObject) new JSONParser().parse(result); boolean success = (Boolean) object.get("success"); if (!success) System.err.println(object.get("error")); return success; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:org.opencastproject.sox.remote.SoxServiceRemoteImpl.java
/** * {@inheritDoc}/*from w ww . ja v a 2 s . c o m*/ * * @see org.opencastproject.sox.api.SoxService#analyze(Track) */ @Override public Job analyze(Track sourceAudioTrack) throws MediaPackageException, SoxException { HttpPost post = new HttpPost("/analyze"); try { List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("sourceAudioTrack", MediaPackageElementParser.getAsXml(sourceAudioTrack))); post.setEntity(new UrlEncodedFormEntity(params)); } catch (Exception e) { throw new SoxException(e); } HttpResponse response = null; try { response = getResponse(post); if (response != null) { try { Job receipt = JobParser.parseJob(response.getEntity().getContent()); logger.info("Analyzing audio {} on a remote analysis server", sourceAudioTrack); return receipt; } catch (Exception e) { throw new SoxException("Unable to analyze audio of element '" + sourceAudioTrack + "' using a remote analysis service", e); } } } finally { closeConnection(response); } throw new SoxException( "Unable to analyze audio of element '" + sourceAudioTrack + "' using a remote analysis service"); }
From source file:uk.submergedcode.SubmergedCore.error.ReportExceptionRunnable.java
public boolean run() { try {/*from w ww .j a v a 2 s. c o m*/ List<NameValuePair> data = new ArrayList<NameValuePair>(); data.add(new BasicNameValuePair("password", DigestUtils.md5Hex(SubmergedCore.getConfigurationManager().getCrashPassword()))); data.add(new BasicNameValuePair("project", "SubmergedCore")); data.add(new BasicNameValuePair("cause", getException(throwable))); data.add(new BasicNameValuePair("message", getMessage(throwable))); data.add(new BasicNameValuePair("st", buildStackTrace(throwable))); HttpPost post = new HttpPost("http://server.mcbadgercraft.com/crash/report.php"); post.setEntity(new UrlEncodedFormEntity(data)); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse responce = client.execute(post); String result = EntityUtils.toString(responce.getEntity()); if (SubmergedCore.getConfigurationManager().isDebugEnabled()) System.out.println(result); JSONObject object = (JSONObject) new JSONParser().parse(result); boolean success = (Boolean) object.get("success"); if (!success) System.err.println(object.get("error")); return success; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:com.jimkont.contactFix.provider.ProviderHTTPPost.java
/** * Connects to the server//from w w w . j a v a 2s .c o m */ public static String executePost(String url, ArrayList<NameValuePair> params) { final ResponseHandler<String> responseHandler; HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params); } catch (final UnsupportedEncodingException e) { // this should never happen. throw new AssertionError(e); } final HttpPost post = new HttpPost(url); post.addHeader(entity.getContentType()); post.setEntity(entity); maybeCreateHttpClient(); try { responseHandler = new BasicResponseHandler(); String responseBody = mHttpClient.execute(post, responseHandler); return responseBody; } catch (final IOException e) { return null; } finally { } }
From source file:edu.rit.csh.androidwebnews.HttpsPostAsyncTask.java
/** * The method that gets run when execute() is run. This sends the URL with the * POST parameters to the server and gets the results * * @param params - [0] is the URL to got to, the rest are parameters to the request * @return String representation of page results *//*w w w .jav a2s. co m*/ @Override protected String doInBackground(BasicNameValuePair... params) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); String line; try { HttpPost request = new HttpPost(params[0].getValue()); request.addHeader("accept", "application/json"); //params = Arrays.copyOfRange(params, 1, params.length); for (BasicNameValuePair pair : params) { nvp.add(new BasicNameValuePair(pair.getName(), pair.getValue())); } request.setEntity(new UrlEncodedFormEntity(nvp)); HttpResponse response = httpclient.execute(request); BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder sb = new StringBuilder(""); String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line).append(NL); } in.close(); String page = sb.toString(); Log.d("jd - post result", " : " + page); return page; } catch (ClientProtocolException e) { Log.d("jd - post error", e.toString()); } catch (ConnectTimeoutException e) { Log.d("jd - post timeout error ", e.toString()); doInBackground(params); } catch (IOException e) { Log.d("jd - post error", e.toString()); } return ""; }
From source file:com.example.pyrkesa.shwc.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try {/*from w ww .j a v a 2 s . co m*/ // check for request method if (method == "POST") { // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; }
From source file:com.riksof.a320.c2dm.common.C2DMReceiver.java
@Override public void onRegistered(Context context, String registrationId) { HttpClient httpclient = new DefaultHttpClient(); Log.w("C2DMReceiver-onRegistered", "Sending request to Server"); HttpPost httppost = new HttpPost(getResources().getString(R.string.server_url)); // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("deviceToken", registrationId)); nameValuePairs.add(new BasicNameValuePair("sdkType", "Android")); nameValuePairs.add(new BasicNameValuePair("openUDID", getOpenUDID(this.getBaseContext()))); nameValuePairs.add(new BasicNameValuePair("deviceId", getAndroidId(this.getBaseContext()))); try {//from w w w .j a v a 2 s . com httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { HttpResponse response = httpclient.execute(httppost); System.out.println(response); } catch (Exception e) { Log.e("C2DMReceiver-onRegistered", e.getMessage()); } Log.w("C2DMReceiver-onRegistered", registrationId); }
From source file:com.citruspay.mobile.payment.client.rest.RESTClient.java
public JSONObject post(URI path, Collection<Header> headers, Map<String, String> params) throws ProtocolException, RESTException { // convert params List<NameValuePair> pairs = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> param : params.entrySet()) { pairs.add(new BasicNameValuePair(param.getKey(), param.getValue())); }/* w ww . j a va 2 s. com*/ // create request + entity HttpPost post = new HttpPost(uri.resolve(path)); try { post.setEntity(new UrlEncodedFormEntity(pairs)); } catch (UnsupportedEncodingException uex) { throw new ProtocolException(uex); } // execute request return execute(post, headers); }
From source file:com.frapim.windwatch.Http.java
/** * Making service call/*from w ww. j av a 2 s . co m*/ * @url - url to make request * @method - http request method * @params - http request params * */ public String request(String url, int method, List<NameValuePair> params) { try { // http client DefaultHttpClient httpClient = new DefaultHttpClient(); HttpEntity httpEntity = null; HttpResponse httpResponse = null; // Checking http request method type if (method == POST) { HttpPost httpPost = new HttpPost(url); // adding post params if (params != null) { httpPost.setEntity(new UrlEncodedFormEntity(params)); } httpResponse = httpClient.execute(httpPost); } else if (method == GET) { // appending params to url if (params != null) { String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; } HttpGet httpGet = new HttpGet(url); httpResponse = httpClient.execute(httpGet); } httpEntity = httpResponse.getEntity(); response = EntityUtils.toString(httpEntity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return response; }