Example usage for org.apache.http.client.methods HttpPost HttpPost

List of usage examples for org.apache.http.client.methods HttpPost HttpPost

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPost HttpPost.

Prototype

public HttpPost() 

Source Link

Usage

From source file:Main.java

public static String responseContentUri(URI uri) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost request = new HttpPost();
    request.setURI(uri);//from   w w  w .  j ava 2s . c o m
    InputStream is = client.execute(request).getEntity().getContent();
    BufferedReader inb = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder("");
    String line;
    String NL = System.getProperty("line.separator");
    while ((line = inb.readLine()) != null) {
        sb.append(line).append(NL);
    }
    inb.close();
    return sb.toString();
}

From source file:Main.java

public static byte[] doPostSubmit(String url, List<NameValuePair> params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost();
    try {//from   w  ww . j a v a 2s  .  c o  m
        httpPost.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
        HttpResponse response = httpClient.execute(httpPost);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            return EntityUtils.toByteArray(entity);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.opencastproject.util.HttpUtil.java

public static HttpPost post(NameValuePair... formParams) {
    final HttpPost post = new HttpPost();
    setFormParams(post, formParams);//www.  j a v a 2  s.  c om
    return post;
}

From source file:Main.java

public static byte[] doPostSubmit(String url, Map<String, Object> params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost();
    try {/*from w  ww  .j  a v  a 2 s.c  o  m*/

        List<NameValuePair> list = new ArrayList<NameValuePair>();

        for (Entry<String, Object> entry : params.entrySet()) {
            NameValuePair nameValuePair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
            list.add(nameValuePair);
        }
        httpPost.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
        HttpResponse response = httpClient.execute(httpPost);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            return EntityUtils.toByteArray(entity);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.github.yongchristophertang.engine.web.request.TestRequestBuilders.java

/**
 * Create a {@link HttpRequestBuilders} for a POST request.
 *
 * @param urlTemplate  a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 *///from w ww . j  av a  2 s.c om
public static HttpRequestBuilders post(String urlTemplate, Object... urlVariables) {
    return new HttpRequestBuilders(new HttpPost(), urlTemplate, "POST Request", urlVariables);
}

From source file:com.github.restdriver.serverdriver.http.RequestBodyTest.java

@Test
public void bodyAppliesItselfToRequest() throws Exception {
    HttpPost request = new HttpPost();
    RequestBody body = new RequestBody("content", "content/type");
    body.applyTo(new ServerDriverHttpUriRequest(request));
    assertThat(IOUtils.toString(request.getEntity().getContent()), is("content"));
    assertThat(request.getEntity().getContentType().getValue(), is("content/type; charset=UTF-8"));
    assertThat(request.getFirstHeader("Content-type").getValue(), is("content/type"));
}

From source file:org.aicer.hibiscus.http.workers.HttpWorkerPost.java

public HttpWorkerPost(HttpClient client) {
    super(client, new HttpPost());
}

From source file:com.github.restdriver.serverdriver.http.ByteArrayRequestBodyTest.java

@Test
public void bodyAppliesItselfToRequest() throws Exception {
    byte[] bytes = "MY STRING OF DOOM!".getBytes();
    HttpPost request = new HttpPost();
    ByteArrayRequestBody body = new ByteArrayRequestBody(bytes, "contentType");
    body.applyTo(new ServerDriverHttpUriRequest(request));
    assertThat(IOUtils.toString(request.getEntity().getContent()), is("MY STRING OF DOOM!"));
    assertThat(request.getEntity().getContentType().getValue(), is("contentType"));
    assertThat(request.getFirstHeader("Content-type").getValue(), is("contentType"));
}

From source file:it.govpay.web.console.utils.HttpClientUtils.java

public static HttpResponse sendRichiestaPagamento(String urlToInvoke, RichiestaPagamento richiestaPagamento,
        Logger log) throws Exception {
    HttpResponse responseGET = null;//from  w  ww . ja  va2 s . com
    try {
        log.debug("Invio del pagamento in corso...");

        URL urlObj = new URL(urlToInvoke);
        HttpHost target = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol());
        CloseableHttpClient client = HttpClientBuilder.create().disableRedirectHandling().build();
        HttpPost richiestaPost = new HttpPost();

        richiestaPost.setURI(urlObj.toURI());

        log.debug("Serializzazione pagamento in corso...");
        byte[] bufferPagamento = JaxbUtils.toBytes(richiestaPagamento);
        log.debug("Serializzazione pagamento completata.");

        HttpEntity bodyEntity = new InputStreamEntity(new ByteArrayInputStream(bufferPagamento),
                ContentType.APPLICATION_XML);
        richiestaPost.setEntity(bodyEntity);
        richiestaPost.setHeader("Content-Type", ContentType.APPLICATION_XML.getMimeType());

        log.debug("Invio tramite client Http in corso...");
        responseGET = client.execute(target, richiestaPost);

        if (responseGET == null)
            throw new NullPointerException("La Response HTTP e' null");

        log.debug("Invio tramite client Http completato.");
        return responseGET;
    } catch (Exception e) {
        log.error("Errore durante l'invio della richiesta di pagamento: " + e.getMessage(), e);
        throw e;
    }
}

From source file:HttpConnections.RestRequester.java

public RestRequester() {
    this.uri = new DiffURIBuilder();
    this.RC = new ResponseContents();
    this.httpget = new HttpGet();
    this.httpput = new HttpPut();
    this.httppost = new HttpPost();
    this.soapPost = new SoapPost();
    this.method = "";
}