List of usage examples for org.apache.http.client.methods HttpPost HttpPost
public HttpPost(final String uri)
From source file:org.sharetask.data.IntegrationTest.java
@BeforeClass public static void login() throws Exception { final DefaultHttpClient client = new DefaultHttpClient(); final HttpPost httpPost = new HttpPost(BASE_URL + "/user/login"); httpPost.addHeader(new BasicHeader("Content-Type", "application/json")); final StringEntity httpEntity = new StringEntity( "{\"username\":\"dev1@shareta.sk\"," + "\"password\":\"password\"}"); System.out.println(EntityUtils.toString(httpEntity)); httpPost.setEntity(httpEntity);// ww w . ja va 2 s .c o m //when final HttpResponse response = client.execute(httpPost); //then Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode()); client.getCookieStore().getCookies(); for (final Cookie cookie : client.getCookieStore().getCookies()) { if (cookie.getName().equals("JSESSIONID")) { DOMAIN = cookie.getDomain(); SESSIONID = cookie.getValue(); } } }
From source file:br.com.estudogrupo.online.DicionarioOnline04.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.md5online.org/"); try {/*from ww w . j a va 2 s. co m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("md5", getRecebe())); nameValuePairs.add(new BasicNameValuePair("search", "0")); nameValuePairs.add(new BasicNameValuePair("action", "decrypt")); nameValuePairs.add(new BasicNameValuePair("a", "82355607")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine().trim()) != null) { if (line.startsWith("<span class=\"result\"")) { String key = line.substring(81, 100); System.out.println("Senha : " + key.trim().replace("</b>", "").replace("</s>", "") .replace("</span><br", "").replace(" /", "")); } } } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { } }
From source file:monitor.console.control.HTTPRequest.java
public HTTPRequest(String login, byte[] password, FindUrl url) throws UnsupportedEncodingException, IOException { HttpClient client = new DefaultHttpClient(); System.out.println(url.getHostName() + ":" + url.getPortNumber() + "/" + url.getRestServiceName()); HttpPost post = new HttpPost( url.getHostName() + ":" + url.getPortNumber() + "/" + url.getRestServiceName()); StringEntity input = new StringEntity( "{\"login\":" + "\"" + login + "\",\"password\":\"" + Arrays.toString(password) + "\"}"); input.setContentType("application/json"); post.setEntity(input);//from w w w. j a va 2 s . c om HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String tmp = ""; while ((tmp = rd.readLine()) != null) { resp = tmp.replaceAll("\"", ""); System.out.println(resp); } }
From source file:text_analytics.OpenCalaisKE.java
private HttpPost postMethod(String content) { postMethod = new HttpPost(CALAIS_URL); // Set mandatory parameters postMethod.addHeader("x-calais-licenseID", licenseID); postMethod.addHeader("Content-type", "text/raw; charset=UTF-8"); // 3. Document content should be passed as the body of the HTTP request. StringEntity se = new StringEntity(content, ContentType.create("text/plain", "UTF-8")); postMethod.setEntity(se);//from ww w . ja v a2s .c o m // Set response/output format //postMethod.addHeader("Accept", "xml/rdf"); postMethod.addHeader("Accept", "application/json"); // Enable Social Tags processing postMethod.addHeader("enableMetadataType", "SocialTags"); return postMethod; }
From source file:aop.controller.RequestController.java
public void sendPostReq(int id, String type) throws Exception { boolean debug = false; String url = "http://localhost:1337/"; CloseableHttpClient httpClient = HttpClients.createDefault(); try {//from www . j a v a 2s . co m HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("id", Integer.toString(id))); urlParameters.add(new BasicNameValuePair("type", type)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = httpClient.execute(post); if (debug) { System.out.println("\nSending 'POST' request to URL : " + url); 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()); } } finally { httpClient.close(); } }
From source file:br.com.estudogrupo.online.DicionarioOnline02.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.md5pass.info"); try {/* w w w . j a v a2 s.c om*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("hash", getRecebe())); nameValuePairs.add(new BasicNameValuePair("get_pass", "Get+Pass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { if (line.startsWith("Password -")) { System.out.println("Senha : " + line.replace("<b>", "").replace("</b>", "").replace("-", "").replace("Password", "")); System.exit(0); } } } catch (IOException | NullPointerException e) { e.printStackTrace(); } }
From source file:cardgametrackercs319.DBConnectionManager.java
public static String registerUserInfo(String id, String name, String pwd) throws UnsupportedEncodingException, IOException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://ozymaxx.net/cs319/register_user.php"); post.setHeader("User Agent", USER_AGENT); ArrayList<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("id", id)); urlParameters.add(new BasicNameValuePair("pname", name)); urlParameters.add(new BasicNameValuePair("pwd", pwd)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String res = ""; while ((res = reader.readLine()) != null) { result.append(res);//from w ww .j a v a2s .com } return result.toString(); }
From source file:ADP_Streamline.CURL2.java
public String uploadFiles(File file, String siteId, String containerId, String uploadDirectory) { String json = null;// ww w .ja va 2 s . c o m DefaultHttpClient httpclient = new DefaultHttpClient(); HttpHost targetHost = new HttpHost("localhost", 8080, "http"); try { HttpPost httppost = new HttpPost("/alfresco/service/api/upload?alf_ticket=" + this.ticket); FileBody bin = new FileBody(file); StringBody siteid = new StringBody(siteId); StringBody containerid = new StringBody(containerId); StringBody uploaddirectory = new StringBody(uploadDirectory); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("filedata", bin); reqEntity.addPart("siteid", siteid); reqEntity.addPart("containerid", containerid); reqEntity.addPart("uploaddirectory", uploaddirectory); httppost.setEntity(reqEntity); //log.debug("executing request:" + httppost.getRequestLine()); HttpResponse response = httpclient.execute(targetHost, httppost); HttpEntity resEntity = response.getEntity(); //log.debug("response status:" + response.getStatusLine()); if (resEntity != null) { //log.debug("response content length:" + resEntity.getContentLength()); json = EntityUtils.toString(resEntity); //log.debug("response content:" + json); } EntityUtils.consume(resEntity); } catch (Exception e) { throw new RuntimeException(e); } finally { httpclient.getConnectionManager().shutdown(); } return json; }
From source file:br.com.estudogrupo.online.DicionarioOnline03.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.cloudcracker.net/index.php"); try {//from www . java 2s . co m List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("inputbox", getRecebe())); nameValuePairs.add(new BasicNameValuePair("submit", "Crack+MD5+Hash")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine().trim()) != null) { if (line.startsWith("Word:")) { String key = line.substring(96); System.out.println("Senha : " + key.replace("\"", "").replace("/>", "")); System.exit(0); } } } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { } }
From source file:ch.ffhs.esa.bewegungsmelder.tasks.POSTTask.java
protected String doInBackground(String... params) { Log.d("POSTTask", "Running async request.."); HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://" + params[0] + ":" + params[1] + "/ping"); try {/* w w w. ja v a 2 s . c o m*/ List<NameValuePair> data = new ArrayList<NameValuePair>(0); httpPost.setEntity(new UrlEncodedFormEntity(data)); httpClient.execute(httpPost); } catch (UnsupportedEncodingException e) { } catch (IOException e) { } return null; }