List of usage examples for org.apache.http.client.methods HttpPost HttpPost
public HttpPost(final String uri)
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);/*from w w w . j a 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.dnastack.bob.service.processor.util.HttpUtils.java
private static HttpPost createPost(String url, List<NameValuePair> data) throws UnsupportedEncodingException { HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(data)); return httpPost; }
From source file:io.tourniquet.junit.http.rules.examples.HttpClientHelper.java
public static HttpPost post(String url, InputStream data) throws UnsupportedEncodingException { HttpPost post = new HttpPost(url); post.setEntity(new InputStreamEntity(data)); return post;/*from w ww . j a v a2s . c o m*/ }
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:io.kahu.hawaii.util.call.http.SoapRequest.java
public SoapRequest(RequestDispatcher requestDispatcher, RequestContext<T> context, String url, String content, String soapAction, ResponseHandler<HttpResponse, T> responseHandler, CallLogger<T> logger) { super(requestDispatcher, context, responseHandler, new HttpPost(url), logger); HttpEntity httpEntity = new StringEntity(content, ContentType.create("text/xml", "UTF-8")); getHttpRequest().setHeader("Content-Type", "text/xml;charset=UTF-8"); getHttpRequest().setHeader("SOAPAction", '"' + soapAction + '"'); ((HttpPost) getHttpRequest()).setEntity(httpEntity); }
From source file:com.bluehermit.apps.module.soap.client.HttpClientHelperImpl.java
public String post(String target, String message) throws Exception { String responeMessage = null; CloseableHttpClient httpclient = HttpClients.createDefault(); try {/* www . j a va 2 s . co m*/ HttpPost httppost = new HttpPost(target); httppost.setHeader("Content-Type", "text/xml"); httppost.setEntity(new StringEntity(message)); System.out.println("Executing request " + httppost.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httppost); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { responeMessage = IOUtils.toString(instream, "UTF-8"); // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } } } finally { response.close(); } } finally { httpclient.close(); } return responeMessage; }
From source file:com.arrow.acn.client.api.CoreUserApi.java
public StatusModel syncSamlAccounts(List<SamlAccountModel> samlAccounts) { String method = "syncSamlAccounts"; try {/*www . ja va 2 s . c o m*/ URI uri = buildUri(SYNC_SAML_ACCOUNTS_URL); StatusModel result = execute(new HttpPost(uri), JsonUtils.toJson(samlAccounts), StatusModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
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 {/* w ww . j a va 2 s . c o m*/ client.execute(httpPost); } catch (IOException ex) { Logger.getLogger(GCM.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.com.atmatech.sac.webService.WebServiceFinanceiro.java
public List<FinanceiroBeans> getFinanceiro(String url, String user, String password) throws IOException { String chave = ""; HttpPost post = new HttpPost(url); boolean result = false; /* Configura os parmetros do POST */ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("login", user)); nameValuePairs.add(new BasicNameValuePair("senha", password)); nameValuePairs.add(new BasicNameValuePair("x", "26")); nameValuePairs.add(new BasicNameValuePair("y", "26")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); // post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"); HttpResponse response = client.execute(post); // System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(response.getEntity()); HttpPost get = new HttpPost("http://atma.serveftp.com/atma/view/index.php?page=BAIXAR&mostrar=1"); get.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); response = client.execute(get);/*from ww w. j av a 2s . com*/ BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; // // Grava pagina no arquivo FileWriter out = new FileWriter("./logfin.txt"); PrintWriter gravarArq = new PrintWriter(out); int indexant = 11; boolean doc = true; boolean cliente = true; boolean valor = true; boolean vencimento = true; boolean contato = true; boolean tel = true; String tdoc = ""; String tcliente = ""; float tvalor = 0; Date tvencimento = null; String tcontato = ""; String ttel = ""; List<FinanceiroBeans> lfb = new ArrayList<>(); while ((line = rd.readLine()) != null) { if (line.contains("<tr><td>")) { //gravarArq.print(line+"\n"); line = line.replace("<tr><td>", "\n").replace("</td></tr>", "\n"); line = line.replace("</td><td>", ";") .replace("</td><td align='center'><a class='btn default' target='_blank'", ";") .replace("</i></a>", ":"); gravarArq.print(line + "\n"); for (int i = 0; i < line.length(); i++) { if (doc && (indexant != i)) { if (line.charAt(i) == ';') { tdoc = line.substring(indexant + 1, i); indexant = i; doc = false; } } else { if ((!doc) && (cliente) && (indexant != i)) { if (line.charAt(i) == ';') { tcliente = line.substring(indexant + 1, i); indexant = i; cliente = false; } } else { if ((!doc) && (!cliente) && (valor) && (indexant != i)) { if (line.charAt(i) == ';') { tvalor = Float.valueOf(line.substring(indexant + 1, i)); indexant = i; valor = false; } } else { if ((!doc) && (!cliente) && (!valor) && (vencimento) && (indexant != i)) { if (line.charAt(i) == ';') { String data = line.substring(indexant + 1, i).replace("/", "."); int ind1 = data.indexOf("."); int ind2 = data.indexOf(".", ind1 + 1); String dd = data.substring(0, ind1); String mm = data.substring(ind1 + 1, ind2); String yyyy = data.substring(ind2 + 1); tvencimento = new Date(Integer.parseInt(yyyy) - 1900, Integer.parseInt(mm) - 1, Integer.parseInt(dd)); indexant = i; vencimento = false; } } else { if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (contato) && (indexant != i)) { if (line.charAt(i) == ';') { tcontato = line.substring(indexant + 1, i); indexant = i; contato = false; } } else { if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato) && (tel) && (indexant != i)) { if (line.charAt(i) == ';') { ttel = line.substring(indexant + 1, i); indexant = i; tel = false; } } else { if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato) && (!tel) && (line.charAt(i) == ':')) { indexant = i + 2; FinanceiroBeans fb = new FinanceiroBeans(); fb.setCliente(tcliente); fb.setContato(tcontato); fb.setDoc(tdoc); fb.setTelcel(ttel); fb.setValor(tvalor); fb.setVencimento(tvencimento); lfb.add(fb); doc = true; cliente = true; valor = true; vencimento = true; contato = true; tel = true; } } } } } } } } } } out.close(); return lfb; }
From source file:cn.loveapple.client.android.util.ApiUtil.java
public static String getHttpBody(String url, PackageManager packageManager) { if (StringUtils.isEmpty(url)) { return null; }//from w w w.j a va 2s .co m String body = null; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); // SYSTEM INFO params.setParameter("", ""); params.setParameter("", ""); params.setParameter("", ""); HttpConnectionParams.setConnectionTimeout(params, 1000); HttpConnectionParams.setSoTimeout(params, 1000); HttpPost httpRequest = new HttpPost(url); HttpResponse httpResponse = null; try { httpResponse = httpClient.execute(httpRequest); } catch (Exception e) { Log.e(LOG_TAG, "http response execute failed.", e); return null; } if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity httpEntity = httpResponse.getEntity(); try { body = EntityUtils.toString(httpEntity); } catch (Exception e) { Log.e(LOG_TAG, "get http response body failed.", e); return null; } finally { try { httpEntity.consumeContent(); } catch (IOException e) { } } } httpClient.getConnectionManager().shutdown(); return body; }