List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters)
From source file:com.clarionmedia.infinitum.http.rest.impl.RestfulNameValueModelMap.java
@Override public HttpEntity toHttpEntity() { try {/* w ww. jav a 2 s. c o m*/ return new UrlEncodedFormEntity(mNameValuePairs); } catch (UnsupportedEncodingException e) { return null; } }
From source file:org.opencastproject.remotetest.server.resource.SchedulerResources.java
public static HttpResponse findConflictingEvents(TrustedHttpClient client, String event) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "findConflictingEvents"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("event", event)); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }
From source file:net.ccghe.utils.Server.java
public static JSONObject Send(PostDataPairs pairs) { HttpClient client = new DefaultHttpClient(); try {/*w w w . ja v a2 s.c o m*/ HttpPost post = new HttpPost(serverURL); post.setEntity(new UrlEncodedFormEntity(pairs.get())); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); String jsonResponse = convertStreamToString(stream); stream.close(); if (entity != null) { entity.consumeContent(); } JSONObject jObject = new JSONObject(jsonResponse); return jObject; } catch (ClientProtocolException e) { Log.e("EMOCHA", "ClientProtocolException ERR. " + e.getMessage()); } catch (UnknownHostException e) { Log.e("EMOCHA", "UnknownHostException ERR. " + e.getMessage()); } catch (IOException e) { Log.e("EMOCHA", "IOException ERR. " + e.getMessage()); } catch (Exception e) { Log.e("EMOCHA", "Exception ERR. " + e.getMessage()); } return null; }
From source file:org.opencastproject.remotetest.server.resource.ComposerResources.java
public static HttpResponse image(TrustedHttpClient client, String mediapackage, String time, String sourceTrackId, String profileId) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "encode"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("mediapackage", mediapackage)); params.add(new BasicNameValuePair("sourceTrackId", sourceTrackId)); params.add(new BasicNameValuePair("time", time)); params.add(new BasicNameValuePair("profileId", profileId)); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }
From source file:edgeserver.HTTPClient.java
void sendPost(String url, List<NameValuePair> postParams) throws Exception { int CONNECTION_TIMEOUT = 30 * 1000; // timeout in millis RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(CONNECTION_TIMEOUT) .setConnectTimeout(CONNECTION_TIMEOUT).setSocketTimeout(CONNECTION_TIMEOUT).build(); //System.out.println(postParams); HttpPost post = new HttpPost(url); post.setConfig(requestConfig);/*w w w. ja v a 2 s .c o m*/ // add header post.setHeader("Host", "localhost"); post.setHeader("User-Agent", USER_AGENT); post.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); post.setHeader("Accept-Language", "en-US,en;q=0.5"); post.setHeader("Cookie", getCookies()); post.setHeader("Connection", "keep-alive"); post.setHeader("Referer", "http://localhost/exehdager-teste/index.php/ci_login"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); post.setEntity(new UrlEncodedFormEntity(postParams)); HttpResponse response = client.execute(post); int responseCode = response.getStatusLine().getStatusCode(); //System.out.println("\nSending 'POST' request to URL : " + url); //System.out.println("Post parameters : " + postParams); //System.out.println("Response Code : " + responseCode); 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()); }
From source file:com.github.robozonky.integrations.zonkoid.UtilTest.java
@Test void responseContent() { final Collection<NameValuePair> nvp = Collections.singletonList(new BasicNameValuePair("key", "value")); final HttpEntity e = new UrlEncodedFormEntity(nvp); assertThat(Util.readEntity(e)).isNotEmpty(); }
From source file:fr.qinder.api.APIGetter.java
protected HttpsURLConnection post(String sUrl, APIRequest request) { HttpsURLConnection urlConnection; URL url;/*from ww w. j a va2 s . c om*/ try { url = new URL(sUrl); urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); if (request.getPosts().size() != 0) { urlConnection.setRequestMethod("POST"); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(request.getPosts()); OutputStream post = urlConnection.getOutputStream(); entity.writeTo(post); post.flush(); } urlConnection.connect(); } catch (IOException e) { urlConnection = null; } return urlConnection; }
From source file:com.grinnellplans.plandroid.PlanFetchTask.java
protected String doInBackground(String... params) { Log.i("PlanFetchTask::doInBackground", "Started"); AndroidHttpClient plansClient = AndroidHttpClient.newInstance("plandroid"); final HttpPost req = new HttpPost("http://" + _ss.get_serverName() + "/api/1/index.php?task=read"); List<NameValuePair> postParams = new ArrayList<NameValuePair>(1); postParams.add(new BasicNameValuePair("username", params[0])); postParams.add(new BasicNameValuePair("readlinkreplacement", "/plan/{username}")); Log.i("PlanFetchTask::doInBackground", "setting postParams"); try {/*from w ww. j a v a 2 s. co m*/ req.setEntity(new UrlEncodedFormEntity(postParams)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } HttpResponse response = null; try { Log.i("PlanFetchTask::doInBackground", "executing request"); response = plansClient.execute(req, _httpContext); } catch (IOException e) { e.printStackTrace(); } String resp = null; try { Log.i("PlanFetchTask::doInBackground", "reading response"); resp = new BufferedReader((new InputStreamReader(response.getEntity().getContent()))).readLine(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } plansClient.close(); Log.i("PlanFetchTask::doInBackground", "server responded \"" + resp + "\""); return resp; }
From source file:com.naver.timetable.bo.HttpClientBO.java
public String getHttpBody(String url, String method, List<NameValuePair> param) { HttpClient httpClient = null;//from www.j a v a 2 s.co m HttpResponse httpResponse = null; HttpRequestBase httpRequest; try { if (StringUtils.upperCase(method).equals("POST")) { httpRequest = new HttpPost(url); ((HttpPost) httpRequest).setEntity(new UrlEncodedFormEntity(param)); } else { httpRequest = new HttpGet(url); } TrustManager[] trustManagers = new TrustManager[1]; trustManagers[0] = new DefaultTrustManager(); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(new KeyManager[0], trustManagers, new SecureRandom()); SSLContext.setDefault(sslContext); sslContext.init(null, trustManagers, null); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); // httpClient = HttpClientBuilder.create().build(); httpResponse = httpClient.execute(httpRequest); return EntityUtils.toString(httpResponse.getEntity()); } catch (ClientProtocolException e) { LOG.error("Client protocol error : ", e); } catch (IOException e) { LOG.error("IO error : ", e); } catch (KeyManagementException e) { LOG.error("IO error : ", e); } catch (NoSuchAlgorithmException e) { LOG.error("IO error : ", e); } finally { // ? HttpClientUtils.closeQuietly(httpResponse); HttpClientUtils.closeQuietly(httpClient); } return null; }
From source file:com.odo.kcl.mobileminer.OpenBmapCellRequest.java
@Override protected Object doInBackground(Object... cellSpec) { if (cellSpec.length < 4) return null; String Mcc, Mnc, Lac, Id;//from ww w . j ava2 s . c o m Mcc = (String) cellSpec[0]; Mnc = (String) cellSpec[1]; Lac = (String) cellSpec[2]; Id = (String) cellSpec[3]; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.openbmap.org/api/getGPSfromGSM.php"); List<NameValuePair> postData = new ArrayList<NameValuePair>(4); postData.add(new BasicNameValuePair("mcc", Mcc)); postData.add(new BasicNameValuePair("mnc", Mnc)); postData.add(new BasicNameValuePair("lac", Lac)); postData.add(new BasicNameValuePair("cell_id", Id)); try { String XMLdump, Lat, Long, poly, polyDump; Lat = null; Long = null; poly = null; post.setEntity(new UrlEncodedFormEntity(postData)); XMLdump = EntityUtils.toString(client.execute(post).getEntity()); //Log.i("MobileMiner",XMLdump); Matcher latMatch = latPattern.matcher(XMLdump); while (latMatch.find()) Lat = latMatch.group(1); Matcher longMatch = longPattern.matcher(XMLdump); while (longMatch.find()) Long = longMatch.group(1); Matcher polyMatch = polyPattern.matcher(XMLdump); while (polyMatch.find()) poly = polyMatch.group(1); //Log.i("MobileMiner","Lat "+Lat); //Log.i("MobileMiner","Long "+Long); //Log.i("MobileMiner","Poly "+poly); if (poly != null) { List<String> points = new ArrayList<String>(); String[] point; String[] polyChunks = poly.split(","); for (String chunk : polyChunks) { point = chunk.split("\\s+"); points.add("[" + point[1] + "," + point[0] + "]"); } polyDump = "[" + TextUtils.join(",", points.subList(0, points.size() - 1)) + "]"; //Log.i("MobileMiner",polyDump); } else { polyDump = null; } if (Lat != null && Long != null) { return new String[] { Lat, Long, polyDump }; } else { return null; } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block } // TODO Auto-generated method stub return null; }