List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters)
From source file:gcm_projeto_integracao.GCM.java
public void SendMSG(String registrationID, String mensagem) throws UnsupportedEncodingException { CloseableHttpClient client = HttpClients.createDefault(); List<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("registration_id", registrationID)); list.add(new BasicNameValuePair("data.price", mensagem)); HttpPost httpPost = new HttpPost(uRL); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); httpPost.setHeader("Authorization", "key=" + chave); httpPost.setEntity(new UrlEncodedFormEntity(list)); try {//from w ww . j a v a 2 s . c om client.execute(httpPost); } catch (IOException ex) { Logger.getLogger(GCM.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.opencastproject.remotetest.server.resource.CaptureResources.java
public static HttpResponse stopCapturePost(TrustedHttpClient client, String id) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "stopCapture"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("recordingID", id)); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }
From source file:movie.rating.retriever.JSONResponse.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) throws Exception { // Making HTTP request // 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();//from www . j ava 2 s.co m } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); if (params != null) { 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(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 20); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { System.out.println("Error converting result " + e.toString()); } // try parse the string to a JSON object //System.out.println("JSON String"+ json); try { jObj = new JSONObject(json); } catch (Exception e) { System.out.println("Error parsing data " + e.toString()); } // return JSON String return jObj; }
From source file:org.fcrepo.integration.api.FedoraFieldSearchIT.java
@Test public void testSearchSubmit() throws Exception { final HttpPost method = new HttpPost(serverAddress + "search"); final List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); list.add(new BasicNameValuePair("terms", "")); list.add(new BasicNameValuePair("offset", "0")); list.add(new BasicNameValuePair("maxResults", "1")); final UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(list); method.setEntity(formEntity);/*from w w w. j a va 2s . c om*/ assertEquals(200, getStatus(method)); }
From source file:com.project.utilities.Utilities.java
/** * Sends post request to sepcified URL// w w w . j ava 2s.co m * @param valuePairs * @param postUrl * @return */ public static String postRequest(final List<BasicNameValuePair> valuePairs, final String postUrl) { String responseStr = null; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient = new DefaultHttpClient(); Log.e("POST_REQUEST", "ACTION LOGIN"); HttpPost httppost = new HttpPost(postUrl); try { // Add your data List<NameValuePair> postFields = new ArrayList<NameValuePair>(2); for (BasicNameValuePair nameValuePair : valuePairs) { postFields.add(nameValuePair); } httppost.setEntity(new UrlEncodedFormEntity(postFields)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); responseStr = EntityUtils.toString(response.getEntity()); Log.e("POST_REQUEST", "RESPONSE_CODE: " + response.getStatusLine().getStatusCode() + ""); } catch (ClientProtocolException e) { Log.e("ClientProtocolException", e.getMessage().toString()); } catch (IOException e) { Log.e("IOException", e.getMessage().toString()); } return responseStr; }
From source file:att.jaxrs.client.Content_tag.java
public static String addContent_tag(long content_id, long tag_id) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id))); urlParameters.add(new BasicNameValuePair("tag_id", Long.toString(tag_id))); String resultStr = ""; try {// w w w .j a v a2s . co m DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_CONTENT_TAG_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:com.asposewords.restfulapi.HttpClientClass.java
public String httpPostMethod(String fileName) { HttpClient client = new DefaultHttpClient(); List<NameValuePair> nameValuePairs; HttpPost post = null;/* w w w . ja va 2s . co m*/ String strResponse = "", line = ""; post = new HttpPost("http://localhost:8080/AsposeWords/rest/words/protection"); try { nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("src", fileName)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); while ((line = rd.readLine()) != null) { if (line != null) { strResponse = "" + line; } } } catch (IOException e) { e.printStackTrace(); } return strResponse; }
From source file:com.rogiel.httpchannel.http.PostRequest.java
@Override public HttpResponse request() throws IOException { final HttpPost post = new HttpPost(uri); for (final Header header : headers) { post.addHeader(header);//w w w .j a va 2s . co m } post.setEntity(new UrlEncodedFormEntity(params)); return ctx.client.execute(post); }
From source file:att.jaxrs.client.Content.java
public static String addContent(Content content) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", content.getContent_id().toString())); urlParameters.add(new BasicNameValuePair("level", content.getLevel())); urlParameters.add(new BasicNameValuePair("presenter", content.getPresenter())); urlParameters.add(new BasicNameValuePair("reads", content.getReads())); String resultStr = ""; try {/*w w w . j av a 2 s.c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_CONTENT_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:Conexion.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try {/*from w ww.j a v a2 s . co m*/ // check for request method if (method == "POST") { // request method is POST // defaultHttpClient System.out.println("url es: " + url); 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(); System.out.println(json); } catch (Exception e) { System.out.println("Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { System.out.println("Error parsing data " + e.toString()); } // return JSON String return jObj; }