List of usage examples for org.apache.http.client.fluent Request Post
public static Request Post(final String uri)
From source file:com.ykun.commons.utils.http.HttpClientUtils.java
public static String post(String url, Map<String, String> params) { return execute(Request.Post(url).bodyForm(map2List(params), Consts.UTF_8)); }
From source file:com.enitalk.controllers.youtube.BotAware.java
public void sendMessages(ArrayNode msg) throws IOException, ExecutionException { String auth = botAuth();//w ww .ja v a 2s .co m String tagResponse = Request.Post(env.getProperty("bot.sendMessage")) .addHeader("Authorization", "Bearer " + auth) .bodyString(msg.toString(), ContentType.APPLICATION_JSON).socketTimeout(20000).connectTimeout(5000) .execute().returnContent().asString(); logger.info("SendMsg sent to a bot {}, response {}", msg, tagResponse); }
From source file:org.mule.module.http.functional.listener.HttpListenerUrlEncodedTestCase.java
@Test public void urlEncodedParamsGenerateAMapPayload() throws Exception { final Response response = Request.Post(getListenerUrl()) .bodyForm(new BasicNameValuePair(PARAM_1_NAME, PARAM_1_VALUE), new BasicNameValuePair(PARAM_2_NAME, PARAM_2_VALUE)) .execute();// w w w. j av a 2 s. c o m final MuleMessage receivedMessage = muleContext.getClient().request(VM_OUTPUT_ENDPOINT, 1000); assertThat(receivedMessage.getPayload(), IsInstanceOf.instanceOf(ParameterMap.class)); ParameterMap payloadAsMap = (ParameterMap) receivedMessage.getPayload(); assertThat(payloadAsMap.size(), is(2)); assertThat(payloadAsMap.get(PARAM_1_NAME), Is.is(PARAM_1_VALUE)); assertThat(payloadAsMap.get(PARAM_2_NAME), Is.is(PARAM_2_VALUE)); compareParameterMaps(response, payloadAsMap); }
From source file:com.github.aistomin.jenkins.real.RealJenkins.java
@Override public String version() throws Exception { final Map<String, String> headers = new HashMap<>(); Executor.newInstance(HttpClientBuilder.create().build()).execute(Request.Post(this.base)) .handleResponse(new ResponseHandler<Object>() { public Object handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { for (final Header header : response.getAllHeaders()) { headers.put(header.getName(), header.getValue()); }/* w w w . ja va2s. co m*/ return response; } }); return headers.get("X-Jenkins"); }
From source file:com.twosigma.beakerx.AutotranslationServiceImpl.java
@Override public String update(String name, String json) { try {/*from ww w .ja v a 2 s.c o m*/ String reply = Request.Post(LOCALHOST + this.context.getPort() + AUTOTRANSLTION) .addHeader(AUTHORIZATION, auth()) .bodyString(createBody(name, json), ContentType.APPLICATION_JSON).execute().returnContent() .asString(); if (!reply.equals("ok")) { throw new RuntimeException(reply); } } catch (Exception e) { throw new RuntimeException(e); } return json; }
From source file:es.upm.oeg.examples.watson.service.MachineTranslationService.java
public String translate(String text, String sid) throws IOException, URISyntaxException { logger.info("Text to translate :" + text); logger.info("Translation type :" + sid); List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("txt", text)); qparams.add(new BasicNameValuePair("sid", sid)); qparams.add(new BasicNameValuePair("rt", "text")); Executor executor = Executor.newInstance(); URI serviceURI = new URI(baseURL).normalize(); String auth = username + ":" + password; byte[] responseB = executor.execute(Request.Post(serviceURI) .addHeader("Authorization", "Basic " + Base64.encodeBase64String(auth.getBytes())) .bodyString(URLEncodedUtils.format(qparams, "utf-8"), ContentType.APPLICATION_FORM_URLENCODED)) .returnContent().asBytes();// w w w . j a v a2 s .c o m String response = new String(responseB, "UTF-8"); logger.info("Translation response :" + response); return response; }
From source file:com.jaspersoft.studio.server.utils.HttpUtils.java
public static Request post(String url, ServerProfile sp) throws HttpException, IOException { System.out.println(url);//from w ww . j a v a 2s . c o m return HttpUtils.setRequest(Request.Post(url), sp); }
From source file:org.jboss.pnc.causewayclient.DefaultCausewayClient.java
boolean post(String url, String jsonMessage, String authToken) { Header authHeader = new BasicHeader("Authorization", "Bearer " + authToken); HttpResponse response;//from w ww . j a va2 s .co m try { logger.info("Making POST request to {}.", url); if (logger.isDebugEnabled()) logger.debug("Request body {}.", secureBodyLog(jsonMessage)); response = Request.Post(url).addHeader(authHeader).bodyString(jsonMessage, ContentType.APPLICATION_JSON) .execute().returnResponse(); } catch (IOException e) { logger.error("Failed to invoke remote Causeway.", e); return false; } try { int statusCode = response.getStatusLine().getStatusCode(); logger.info("Response status: {}", statusCode); logger.debug("Response: " + EntityUtils.toString(response.getEntity())); if (!HttpUtils.isSuccess(statusCode)) { return false; } } catch (IOException e) { logger.error("Failed to read Causeway response.", e); return false; } return true; }
From source file:com.ykun.commons.utils.http.HttpClientUtils.java
public static String post(String url) { return execute(Request.Post(url)); }