List of usage examples for org.apache.http.client.methods HttpPost setEntity
public void setEntity(final HttpEntity entity)
From source file:com.splunk.shuttl.server.mbeans.util.EndpointUtils.java
/** * Set data params to a post request./*from w ww . jav a2 s .co m*/ */ public static void setParamsToPostRequest(HttpPost httpPost, List<BasicNameValuePair> postParams) { try { httpPost.setEntity(new UrlEncodedFormEntity(postParams)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:tern.server.nodejs.NodejsTernHelper.java
private static HttpPost createHttpPost(String baseURL, JsonObject doc) throws UnsupportedEncodingException { HttpPost httpPost = new HttpPost(baseURL); httpPost.setEntity(new StringEntity(doc.toString(), UTF_8)); return httpPost; }
From source file:simple.crawler.ext.vanilla.VanillaForumUtil.java
public static HttpContext login(String loginURL, String username, String password) throws Exception { DefaultHttpClient httpclient = HttpClientFactory.getInstance(); CookieStore cookieStore = new BasicCookieStore(); HttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpResponse res = httpclient.execute(new HttpGet(loginURL), httpContext); String html = HttpClientUtil.getContentBodyAsString(res); HtmlParser parser = new HtmlParser(); Document doc = parser.parseNonWellForm(html); ////from ww w. j a v a2 s. com Node loginTransientKey = (Node) XPathUtil.read(doc, "//*[@id=\"Form_TransientKey\"]", XPathConstants.NODE); Node hpt = (Node) XPathUtil.read(doc, "//*[@id=\"Form_hpt\"]", XPathConstants.NODE); Node target = (Node) XPathUtil.read(doc, "//*[@id=\"Form_Target\"]", XPathConstants.NODE); Node clientHour = (Node) XPathUtil.read(doc, "//*[@id=\"Form_ClientHour\"]", XPathConstants.NODE); // List<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("Form/TransientKey", ((Element) loginTransientKey).getAttribute("value"))); list.add(new BasicNameValuePair("Form/hpt", ((Element) hpt).getAttribute("value"))); list.add(new BasicNameValuePair("Form/Target", ((Element) target).getAttribute("value"))); list.add(new BasicNameValuePair("Form/ClientHour", ((Element) clientHour).getAttribute("value"))); list.add(new BasicNameValuePair("Form/Email", "admin")); list.add(new BasicNameValuePair("Form/Password", "admin")); list.add(new BasicNameValuePair("Form/Sign_In", "Sign In")); list.add(new BasicNameValuePair("Form/RememberMe", "1")); list.add(new BasicNameValuePair("Checkboxes[]", "RememberMe")); HttpPost post = new HttpPost(loginURL); post.setEntity(new UrlEncodedFormEntity(list)); res = httpclient.execute(post, httpContext); return httpContext; }
From source file:com.victorkifer.AndroidTemplates.api.Downloader.java
private static HttpResponse makeHttpPostRequest(String url, List<NameValuePair> params) throws IOException { HttpPost httpPost = new HttpPost(url); if (params != null) { httpPost.setEntity(new UrlEncodedFormEntity(params)); }/* w w w .j a v a2s .com*/ Logger.e(TAG, url); return httpClient.execute(httpPost); }
From source file:costumetrade.common.util.HttpClientUtils.java
public static String doPost(String url, HttpEntity httpEntity) { logger.info("?{}....", url); try (CloseableHttpClient httpclient = HttpClients.custom().build();) { HttpPost request = new HttpPost(url); request.setEntity(httpEntity); try (CloseableHttpResponse response = httpclient.execute(request);) { int statusCode = response.getStatusLine().getStatusCode(); logger.info("?{}???{}", url, statusCode); if (HttpStatus.SC_OK == statusCode) { return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name()); }/*from w ww . j a v a2 s .c om*/ throw new RuntimeException(String.format("?%s???%s", url, statusCode)); } } catch (Exception e) { throw new RuntimeException(String.format("%s", url), e); } }
From source file:srdes.menupp.EntreeDbAdapter.java
/** * @brief Create a new review using the title and body provided. If the review is * successfully created return the new rowId for that review, otherwise return * a -1 to indicate failure./*ww w. j a v a2 s. co m*/ * * @param title the title of the note * * @param body the body of the note * * @param entree the name of the entree the review is for * * @param rating the rating given to the entree in the review * * @throws JSONException if cannot get rowID * * @return rowId or -1 if failed */ public static Long createReview(String title, String body, String entree, float rating) throws JSONException { //add column information to pass to database ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair(KEY_TITLE, title)); nameValuePairs.add(new BasicNameValuePair(KEY_BODY, body)); nameValuePairs.add(new BasicNameValuePair(KEY_ENTREE, entree)); nameValuePairs.add(new BasicNameValuePair(KEY_RATING, new Float(rating).toString())); //http post JSONObject response = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(INSERT_REVIEW_SCRIPT); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httppost, responseHandler); response = new JSONObject(responseBody); } catch (ClientProtocolException e) { DebugLog.LOGD("Protocol error in http connection " + e.toString()); } catch (UnsupportedEncodingException e) { DebugLog.LOGD("Encoding error in http connection " + e.toString()); } catch (IOException e) { DebugLog.LOGD("IO error in http connection " + e.toString()); } //rowID encoded in response return (Long) response.get(KEY_ROWID); }
From source file:com.jiuyi.qujiuyi.common.util.WxRefundSSL.java
public final static String post(String entity, String mch_id, Integer clientType) throws Exception { try {//from w w w . j a va 2s . co m KeyStore keyStore = KeyStore.getInstance("PKCS12"); // FileInputStream instream = new FileInputStream(new // File("D:\\apiclient_cert.p12")); FileInputStream instream = null; if (clientType == 0) { instream = new FileInputStream(new File(SysCfg.getString("apiclient.ssl"))); } else { instream = new FileInputStream(new File(SysCfg.getString("apiclient.app.ssl"))); } try { keyStore.load(instream, mch_id.toCharArray()); } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mch_id.toCharArray()).build(); sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } catch (Exception e) { e.printStackTrace(); } CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); String result = ""; try { HttpPost post = new HttpPost(SysCfg.getString("weixin.refund")); post.setEntity(new StringEntity(entity)); CloseableHttpResponse response = httpclient.execute(post); try { HttpEntity resp = response.getEntity(); if (resp != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resp.getContent())); String line = null; while ((line = bufferedReader.readLine()) != null) { result += line; } } EntityUtils.consume(resp); } finally { response.close(); } } finally { httpclient.close(); } return result; }
From source file:de.wdilab.coma.gui.extensions.RemoteRepo.java
public static boolean getRemoteConnection(String s, UUID uid) { UUID uuid;//from w ww . j a va2 s .co m String xslt_text; boolean is_stored = false; xslt_text = s.replaceAll("\"", "\\\""); xslt_text = xslt_text.replaceAll("\'", "\\\'"); uuid = uid; try { File f = new File("helpingFile.csv"); PrintWriter output = new PrintWriter(new FileWriter(f)); output.println("uuid,data"); xslt_text.trim(); xslt_text = xslt_text.replace("\n", "").replace("\r", ""); output.println(uuid + "," + xslt_text); output.close(); HttpClient client = new DefaultHttpClient(); FileEntity entity = new FileEntity(f, ContentType.create("text/plain", "UTF-8")); HttpPost httppost = new HttpPost(url); httppost.setEntity(entity); HttpResponse response = client.execute(httppost); // System.out.println(response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == 200) is_stored = true; f.delete(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } // System.out.println("xslt stored "+is_stored); return is_stored; }
From source file:Extras.JSON.java
public static HttpResponse request(String URL, List parametros) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(URL); HttpResponse response = null;/*from w w w . j a va 2 s . co m*/ try { httppost.setEntity(new UrlEncodedFormEntity(parametros)); response = httpclient.execute(httppost); } catch (Exception e) { System.out.println(e.getMessage()); } return response; }
From source file:LogToFile.java
private static HttpPost Post(String url, HashMap<String, String> params, HashMap<String, ArrayList<String>> arrayParams) { try {//from w w w .j a v a 2 s .c om if (!url.endsWith("/")) url += "/"; List<NameValuePair> params_list = null; if (params != null) { params_list = new LinkedList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } if (arrayParams != null) { if (params_list == null) params_list = new LinkedList<NameValuePair>(); for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet()) for (String value : entry.getValue()) params_list.add(new BasicNameValuePair(entry.getKey(), value)); } HttpPost request = new HttpPost(url); if (params != null) request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8")); return request; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }