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.haulmont.cuba.web.security.idp.IdpSessionPingConnector.java
public void pingIdpSessionServer(String idpSessionId) { log.debug("Ping IDP session {}", idpSessionId); String idpBaseURL = webIdpConfig.getIdpBaseURL(); if (!idpBaseURL.endsWith("/")) { idpBaseURL += "/"; }/* w w w . j ava 2 s. c o m*/ String idpSessionPingUrl = idpBaseURL + "service/ping"; HttpPost httpPost = new HttpPost(idpSessionPingUrl); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.getMimeType()); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity( Arrays.asList(new BasicNameValuePair("idpSessionId", idpSessionId), new BasicNameValuePair( "trustedServicePassword", webIdpConfig.getIdpTrustedServicePassword())), StandardCharsets.UTF_8); httpPost.setEntity(formEntity); HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(); HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager).build(); try { HttpResponse httpResponse = client.execute(httpPost); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode == 410) { // we have to logout user log.debug("IDP session is expired {}", idpSessionId); if (userSessionSource.checkCurrentUserSession()) { authenticationService.logout(); UserSession userSession = userSessionSource.getUserSession(); throw new NoUserSessionException(userSession.getId()); } } if (statusCode != 200) { log.warn("IDP respond status {} on session ping", statusCode); } } catch (IOException e) { log.warn("Unable to ping IDP {} session {}", idpSessionPingUrl, idpSessionId, e); } finally { connectionManager.shutdown(); } }
From source file:org.opencastproject.remotetest.server.SeriesFeedTest.java
@Test public void testEmptySeriesFeed() throws Exception { // Add a series HttpPost postSeries = new HttpPost(BASE_URL + "/series/"); List<NameValuePair> seriesParams = new ArrayList<NameValuePair>(); seriesParams.add(new BasicNameValuePair("series", getSampleSeries())); //seriesParams.add(new BasicNameValuePair("acl", getSampleAcl())); postSeries.setEntity(new UrlEncodedFormEntity(seriesParams, "UTF-8")); HttpResponse response = client.execute(postSeries); response.getEntity().consumeContent(); Assert.assertEquals(201, response.getStatusLine().getStatusCode()); HttpGet get = new HttpGet(BASE_URL + "/feeds/rss/2.0/series/10.245/5819"); response = client.execute(get);/*from w w w. j a v a 2s . com*/ HttpEntity entity = response.getEntity(); String feed = EntityUtils.toString(entity); // Though empty should generate a valid feed for a valid series Assert.assertEquals(200, response.getStatusLine().getStatusCode()); // Remove series HttpDelete del = new HttpDelete(BASE_URL + "/series/10.245/5819"); response = client.execute(del); response.getEntity().consumeContent(); }
From source file:org.opencastproject.remotetest.server.perf.ConcurrentVideosegmenterTest.java
protected HttpPost getPost() throws Exception { HttpPost postEncode = new HttpPost(BASE_URL + "/vsegmenter/analyze"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("track", trackXml)); postEncode.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); return postEncode; }
From source file:jp.co.conit.sss.sn.ex1.util.SNApiUtil.java
private static SNServerResult post(String url, List<NameValuePair> postData, SNServerResult result) { try {/* ww w.j a v a2 s.c om*/ HttpClient httpCli = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(postData, "utf-8")); HttpResponse response = httpCli.execute(post); int status = response.getStatusLine().getStatusCode(); result.mHttpStatus = status; HttpEntity entity = response.getEntity(); if (entity != null) { String responseBodyText = EntityUtils.toString(entity); entity.consumeContent(); httpCli.getConnectionManager().shutdown(); result.mResponseString = responseBodyText; } } catch (Exception e) { result.mCauseException = e; e.printStackTrace(); } return result; }
From source file:foam.zizim.android.net.BoskoiHttpClient.java
public static HttpResponse PostURL(String URL, List<NameValuePair> data, String Referer) throws IOException { BoskoiService.httpRunning = true;/*from w w w. j ava 2s . c o m*/ //Dipo Fix try { //wrap try around because this constructor can throw Error final HttpPost httpost = new HttpPost(URL); //org.apache.http.client.methods. if (Referer.length() > 0) { httpost.addHeader("Referer", Referer); } if (data != null) { try { //NEED THIS NOW TO FIX ERROR 417 httpost.getParams().setBooleanParameter("http.protocol.expect-continue", false); httpost.setEntity(new UrlEncodedFormEntity(data, HTTP.UTF_8)); } catch (final UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); BoskoiService.httpRunning = false; return null; } } // Post, check and show the result (not really spectacular, but works): try { HttpResponse response = BoskoiService.httpclient.execute(httpost); BoskoiService.httpRunning = false; return response; } catch (final Exception e) { } } catch (final Exception e) { e.printStackTrace(); } BoskoiService.httpRunning = false; return null; }
From source file:org.wikipathways.client.utils.Utils.java
public static String update(String url, HttpClient client, Map<String, String> attributes) throws Exception { HttpPost httpost = new HttpPost(url); // Adding all form parameters in a List of type NameValuePair List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (String key : attributes.keySet()) { nvps.add(new BasicNameValuePair(key, attributes.get(key))); }//ww w. jav a 2 s . c om httpost.addHeader("Accept-Encoding", "application/xml"); httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); HttpResponse response = client.execute(httpost); SAXBuilder jdomBuilder = new SAXBuilder(); Document jdomDocument = jdomBuilder.build(response.getEntity().getContent()); String success = jdomDocument.getRootElement().getChildText("success", WSNamespaces.NS1); return success; }
From source file:org.apache.hadoop.gateway.TempletonDemo.java
private void demo(String url) throws IOException { HttpClient client = new DefaultHttpClient(); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("user.name", "hdfs")); parameters.add(new BasicNameValuePair("jar", "wordcount/org.apache.hadoop-examples.jar")); parameters.add(new BasicNameValuePair("class", "org.apache.org.apache.hadoop.examples.WordCount")); parameters.add(new BasicNameValuePair("arg", "wordcount/input")); parameters.add(new BasicNameValuePair("arg", "wordcount/output")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, Charset.forName("UTF-8")); HttpPost request = new HttpPost(url); request.setEntity(entity);/*from www . jav a 2 s . c om*/ HttpResponse response = client.execute(request); System.out.println(EntityUtils.toString(response.getEntity())); }
From source file:autopostsoicomputer.API.WPApi.java
@Override public void createNewPostWP(PostObject po, String strUrlWordpress) throws UnsupportedEncodingException, IOException { strUrlWordpress += "createpost.php"; for (;;) {/* w w w . j a v a 2 s. c o m*/ try { HttpClient client = new DefaultHttpClient(); ////// Get Variable String strPostTitle = po.getPostTitle(); // check if postTitle has posted String strPostImageFeature = po.getPostImageFeature(); String strPostCategory = po.getPostCategory(); String strPostContent = po.getPostContent(); ////// HttpPost post = new HttpPost(strUrlWordpress); // add header post.setHeader("User-Agent", "PosterBotDefault"); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("user", USER)); urlParameters.add(new BasicNameValuePair("pass", PASS)); urlParameters.add(new BasicNameValuePair("post_title", strPostTitle)); urlParameters.add(new BasicNameValuePair("cat", strPostCategory)); urlParameters.add(new BasicNameValuePair("post_content", strPostContent)); urlParameters.add(new BasicNameValuePair("image_future", strPostImageFeature)); post.setEntity(new UrlEncodedFormEntity(urlParameters, "UTF-8")); HttpResponse response = client.execute(post); System.out.println("\nSending 'POST' request to URL : " + strUrlWordpress); 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()); if (response.getStatusLine().getStatusCode() == 200) { ReaderFactory.getInstance().writeFile(strPostTitle); } } catch (Exception ex) { System.out.println("ERROR CREATE POST : " + ex.toString()); count_getPost++; if (count_getPost == maxTries_getPost) { System.out.println("I TRY CREATE POST TO!!! " + strUrlWordpress); count_getPost = 0; break; } else { System.out.println("TRY TIMES : " + count_getPost); createNewPostWP(po, strUrlWordpress); } } finally { break; } } }
From source file:edu.sfsu.cs.orange.ocr.language.TranslatorTinymid.java
static String getTranslatedText(String origText) { String retStr = Translator.BAD_TRANSLATION_MSG; String urlServer = "Your Server Address"; try {/*from w ww.j av a 2s . c om*/ Log.i(TAG, " doInBackground urlServer =" + urlServer); HttpClient httpclient = new DefaultHttpClient(); // specify the URL you want to post to HttpPost httppost = new HttpPost(urlServer); String strMsg = ""; try { // create a list to store HTTP variables and their values List nameValuePairs = new ArrayList(); // add an HTTP variable and value pair nameValuePairs.add(new BasicNameValuePair("origText", origText)); //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); // send the variable and value, in other words post, to the URL HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); switch (responseCode) { case 200: HttpEntity entity = response.getEntity(); if (entity != null) { strMsg = EntityUtils.toString(entity); } break; } } catch (ClientProtocolException e) { // process execption } catch (IOException e) { // process execption } if (strMsg != null && strMsg != "") { JSONObject json_data = new JSONObject(strMsg); String err_cd = json_data.getString("err_cd"); if (err_cd == "1000") ; { retStr = json_data.getString("result");//succeed } } } catch (Exception ex) { System.out.println(ex); } finally { } return retStr; }
From source file:com.googlecode.pondskum.client.FormSubmitterImpl.java
private HttpPost openConnection(final String url, final NameValuePairBuilder nameValuePairBuilder) throws UnsupportedEncodingException { HttpPost httpost = new HttpPost(url); httpost.setEntity(new UrlEncodedFormEntity(nameValuePairBuilder.build(), HTTP.UTF_8)); return httpost; }