List of usage examples for org.apache.http.client.methods HttpPost HttpPost
public HttpPost(final String uri)
From source file:no.hig.gsd.quizgame.ServerUtilities.java
/** * Register this account/device pair within the server. * * @return whether the registration succeeded or not. */// ww w . j a v a 2 s .co m public static String register(final Context context, final String regId) { Log.i("remote", "registering device (regId = " + regId + ")"); String usm = LoginActivity.usm; String retSrc = ""; try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://89.250.116.142/Quizgame/jaxrs/quizgame/gcm"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("username", usm)); nameValuePairs.add(new BasicNameValuePair("regId", regId)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); HttpResponse httpResponse = client.execute(post); HttpEntity entity = httpResponse.getEntity(); retSrc = EntityUtils.toString(entity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (retSrc.equals("success")) { return status = "success"; } else { return status = "failure"; } }
From source file:org.vuphone.assassins.android.http.HTTPPoster.java
public static void doLandMinePost(LandMine lm) { final HttpPost post = new HttpPost(VUphone.SERVER + PATH); post.addHeader("Content-Type", "application/x-www-form-urlencoded"); StringBuffer params = new StringBuffer(); params.append("type=landMinePost&lat=" + lm.getLatitude() + "&lon=" + lm.getLongitude() + "&radius=" + lm.getRadius());//from w ww. ja va 2 s.c o m Log.v(VUphone.tag, pre + "Created parameter string: " + params); post.setEntity(new ByteArrayEntity(params.toString().getBytes())); // Do it Log.i(VUphone.tag, pre + "Executing post to " + VUphone.SERVER + PATH); HttpResponse resp = null; try { resp = c.execute(post); ByteArrayOutputStream bao = new ByteArrayOutputStream(); resp.getEntity().writeTo(bao); Log.d(VUphone.tag, pre + "Response from server: " + new String(bao.toByteArray())); } catch (ClientProtocolException e) { Log.e(VUphone.tag, pre + "ClientProtocolException executing post: " + e.getMessage()); } catch (IOException e) { Log.e(VUphone.tag, pre + "IOException writing to ByteArrayOutputStream: " + e.getMessage()); } catch (Exception e) { Log.e(VUphone.tag, pre + "Other Exception of type:" + e.getClass()); Log.e(VUphone.tag, pre + "The message is: " + e.getMessage()); } }
From source file:org.opf_labs.fmts.fidget.droid.PRONOMSigGenerator.java
/** * @param sigdef//from w w w . j a v a 2s. co m */ public static void generatePRONOMSigFile(SigDefSubmission sigdef) { DefaultHttpClient httpclient = new DefaultHttpClient(); try { HttpPost httpost = new HttpPost(SERVICE_URL); httpost.setEntity(new UrlEncodedFormEntity(createNameValuePairs(sigdef), Consts.UTF_8)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); // Print out: IOUtils.copy(entity.getContent(), System.out); // Finish up: EntityUtils.consume(entity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:org.opencastproject.remotetest.server.resource.SchedulerResources.java
public static HttpResponse updateEvent(TrustedHttpClient client, String event) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "updateEvent"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("event", event)); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }
From source file:io.tourniquet.junit.http.rules.examples.HttpClientHelper.java
public static HttpPost post(String url, String content) throws UnsupportedEncodingException { HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(content)); return post;// w ww .j a va 2 s . c o m }
From source file:es.ucm.look.data.remote.restful.RestMethod.java
/** * Used to insert an element//from www . j a v a 2s . c o m * * @param url * Element URI * @param c * The element represented with a JSON * @return * The response */ public static HttpResponse doPost(String url, JSONObject c) { HttpClient httpclient = new DefaultHttpClient(); HttpPost request = new HttpPost(url); StringEntity s = null; try { s = new StringEntity(c.toString()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } s.setContentEncoding("UTF-8"); s.setContentType("application/json"); request.setEntity(s); request.addHeader("accept", "application/json"); try { return httpclient.execute(request); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:password.pwm.ws.client.rest.RestClientHelper.java
public static String makeOutboundRestWSCall(final PwmApplication pwmApplication, final Locale locale, final String url, final String jsonRequestBody) throws PwmOperationalException, PwmUnrecoverableException { final HttpPost httpPost = new HttpPost(url); httpPost.setHeader("Accept", PwmConstants.AcceptValue.json.getHeaderValue()); if (locale != null) { httpPost.setHeader("Accept-Locale", locale.toString()); }//from ww w . j av a2 s. co m httpPost.setHeader("Content-Type", PwmConstants.ContentTypeValue.json.getHeaderValue()); final HttpResponse httpResponse; try { final StringEntity stringEntity = new StringEntity(jsonRequestBody); stringEntity.setContentType(PwmConstants.AcceptValue.json.getHeaderValue()); httpPost.setEntity(stringEntity); LOGGER.debug("beginning external rest call to: " + httpPost.toString() + ", body: " + jsonRequestBody); httpResponse = PwmHttpClient.getHttpClient(pwmApplication.getConfig()).execute(httpPost); final String responseBody = EntityUtils.toString(httpResponse.getEntity()); LOGGER.trace("external rest call returned: " + httpResponse.getStatusLine().toString() + ", body: " + responseBody); if (httpResponse.getStatusLine().getStatusCode() != 200) { final String errorMsg = "received non-200 response code (" + httpResponse.getStatusLine().getStatusCode() + ") when executing web-service"; LOGGER.error(errorMsg); throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg)); } return responseBody; } catch (IOException e) { final String errorMsg = "http response error while executing external rest call, error: " + e.getMessage(); LOGGER.error(errorMsg); throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg), e); } }
From source file:com.abombrecords.amt_unlocker.AMT_Unlocker.java
public static boolean UnlockDoor(String Username, String Password, String DoorPIN) throws Exception { boolean bSuccess = false; //Log.d(LogTag, "Login"); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpost = new HttpPost("http://acemonstertoys.org/node?destination=node"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("op", "Log in")); nvps.add(new BasicNameValuePair("name", Username)); nvps.add(new BasicNameValuePair("pass", Password)); nvps.add(new BasicNameValuePair("openid.return_to", "http://acemonstertoys.org/openid/authenticate?destination=node")); nvps.add(new BasicNameValuePair("form_id", "user_login_block")); nvps.add(new BasicNameValuePair("form_build_id", "form-4d6478bc67a79eda5e36c01499ba4c88")); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); //Log.d(LogTag, "Login form get: " + response.getStatusLine()); if (entity != null) { entity.consumeContent();/* w ww . ja va 2 s . c o m*/ } //Log.d(LogTag, "Post Login cookies:"); // look for drupal_uid and fail out if it isn't there List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { //Log.d(LogTag, "None"); } else { for (int i = 0; i < cookies.size(); i++) { //Log.d(LogTag, "- " + cookies.get(i).toString()); if (cookies.get(i).getName().equals("drupal_uid")) { bSuccess = true; } } } if (bSuccess) { HttpPost httpost2 = new HttpPost("http://acemonstertoys.org/membership"); List<NameValuePair> nvps2 = new ArrayList<NameValuePair>(); nvps2.add(new BasicNameValuePair("doorcode", DoorPIN)); nvps2.add(new BasicNameValuePair("forceit", "Open Door")); httpost2.setEntity(new UrlEncodedFormEntity(nvps2, HTTP.UTF_8)); response = httpclient.execute(httpost2); entity = response.getEntity(); //Log.d(LogTag, "Unlock form get: " + response.getStatusLine()); if (entity != null) { entity.consumeContent(); } } httpclient.getConnectionManager().shutdown(); return bSuccess; }
From source file:net.bither.http.HttpPostResponse.java
public void handleHttpPost() throws Exception { setHttpClient();/*from w w w . j a v a2 s.co m*/ try { HttpPost httpPost = new HttpPost(getUrl()); httpPost.setHeader("Accept", "application/json"); httpPost.setEntity(getHttpEntity()); HttpResponse httpResponse = getHttpClient().execute(httpPost); String response = getReponse(httpResponse); setResult(response); } catch (Exception e) { throw e; } finally { getHttpClient().getConnectionManager().shutdown(); } }
From source file:org.opencastproject.remotetest.server.resource.CaptureResources.java
public static HttpResponse startCapturePost(TrustedHttpClient client) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "startCapture"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("config", captureProperties())); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }