Example usage for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity

List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity

Introduction

In this page you can find the example usage for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity.

Prototype

public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset) 

Source Link

Document

Constructs a new UrlEncodedFormEntity with the list of parameters in the specified encoding.

Usage

From source file:securitytools.veracode.http.request.GetBuildInfoRequest.java

public GetBuildInfoRequest(String applicationId, String buildId) {
    super("/api/4.0/getbuildinfo.do");

    if (applicationId == null) {
        throw new IllegalArgumentException("Application id cannot be null.");
    }/*from w  w w .ja va2s. c  o m*/

    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    formparams.add(new BasicNameValuePair("app_id", applicationId));

    if (buildId != null) {
        formparams.add(new BasicNameValuePair("build_id", buildId));
    }

    setEntity(new UrlEncodedFormEntity(formparams, Consts.UTF_8));
}

From source file:securitytools.veracode.http.request.DeleteBuildRequest.java

public DeleteBuildRequest(String applicationId, String sandboxId) {
    super("/api/4.0/deletebuild.do");

    if (applicationId == null) {
        throw new IllegalArgumentException("Application id cannot be null.");
    }/*from   w ww  . j  a va  2s . com*/

    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    formparams.add(new BasicNameValuePair("app_id", applicationId));

    if (sandboxId != null) {
        formparams.add(new BasicNameValuePair("sandbox_id", sandboxId));
    }

    setEntity(new UrlEncodedFormEntity(formparams, Consts.UTF_8));
}

From source file:org.fcrepo.integration.webhooks.FedoraWebhooksIT.java

@Test
public void registerWebhookCallbackTest() throws IOException {
    final HttpPost method = new HttpPost(serverAddress + "/fcr:webhooks/callback_id");

    final List<NameValuePair> formparams = new ArrayList<NameValuePair>();

    formparams.add(new BasicNameValuePair("callbackUrl", RESTAPI_NAMESPACE + "/fake:url"));
    final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
    method.setEntity(entity);//from  w w  w.  jav  a2 s . c o  m

    assertEquals(201, getStatus(method));

    final HttpGet displayWebhooks = new HttpGet(serverAddress + "/fcr:webhooks");

    final String content = EntityUtils.toString(client.execute(displayWebhooks).getEntity());

    logger.info("Got content: ");
    logger.info(content);
    assertTrue("Our webhook wasn't registered!",
            compile(RESTAPI_NAMESPACE + "/fake:url", DOTALL).matcher(content).find());

}

From source file:br.com.atmatech.sac.webService.WebServiceCadastro.java

public PessoaBeans postWebService(String cnpj) throws IOException {
    PessoaBeans pb = new PessoaBeans();
    HttpPost post = new HttpPost("http://appasp.sefaz.go.gov.br/Sintegra/Consulta/consultar.asp");
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("rTipoDoc", "2"));
    nameValuePairs.add(new BasicNameValuePair("tDoc", cnpj));
    nameValuePairs.add(new BasicNameValuePair("tCCE", ""));
    nameValuePairs.add(new BasicNameValuePair("tCNPJ", cnpj));
    nameValuePairs.add(new BasicNameValuePair("tCPF", ""));
    nameValuePairs.add(new BasicNameValuePair("btCGC", "Consultar"));
    nameValuePairs.add(new BasicNameValuePair("zion.SystemAction", "consultarSintegra()"));
    nameValuePairs.add(new BasicNameValuePair("zion.OnSubmited", ""));
    nameValuePairs.add(new BasicNameValuePair("zion.FormElementPosted", "zionFormID_1"));
    nameValuePairs.add(new BasicNameValuePair("zionPostMethod", ""));
    nameValuePairs.add(new BasicNameValuePair("zionRichValidator", "true"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    HttpResponse response;/*from   w w w  . j  ava  2s .c om*/

    response = client.execute(post);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String inputLine;
    // Grava pagina no arquivo
    // BufferedWriter out = new BufferedWriter(new FileWriter("./pagina.txt"));
    //        while ((inputLine = rd.readLine()) != null) {
    //            out.write(inputLine);
    //            out.newLine();
    //        }
    // Grava pagina no arquivo
    FileWriter out = new FileWriter("./pagina.txt");
    PrintWriter gravarArq = new PrintWriter(out);
    while ((inputLine = rd.readLine()) != null) {
        gravarArq.print(inputLine + "\n");
    }
    out.close();

    String insc = searchTableWeb("Estadual - CCE :", new BufferedReader(new FileReader("./pagina.txt")));
    if (insc != null) {
        pb.setIe(insc.replaceAll("[.-]", ""));
    }
    pb.setRazao(searchTableWeb("Nome Empresarial:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setEndereco(searchTableWeb("Logradouro:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setNumero(searchTableWeb("mero:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setBairro(searchTableWeb("Bairro:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setDistrito(searchTableWeb("pio:", new BufferedReader(new FileReader("./pagina.txt"))));
    String tel = searchTableWeb("Telefone:", new BufferedReader(new FileReader("./pagina.txt")));
    if (tel != null) {
        pb.setTelefone1(tel.replaceAll("[()]", "").replaceAll(" ", ""));
    }
    return pb;
}

From source file:dk.i2m.drupal.resource.UserResource.java

public void login() throws HttpResponseException, IOException {
    URLBuilder builder = new URLBuilder(getDc().getHostname());
    builder.add(getDc().getEndpoint());/*ww  w  .ja  va 2s  .  co m*/
    builder.add(getAlias());
    builder.add("login");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("username", username));
    nvps.add(new BasicNameValuePair("password", password));

    HttpPost method = new HttpPost(builder.toURI());
    method.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

    ResponseHandler<String> handler = new BasicResponseHandler();
    getDc().getHttpClient().execute(method, handler);
}

From source file:net.ecfirm.ec.ec1.net.EcNetHttpPost.java

@Override
/**/*from   www .  j av  a 2 s. co m*/
 * @TODO test: params type trans from jsonobject to hashmap */
protected InputStream httpPost() throws IOException {
    InputStream inputStream = null;
    DefaultHttpClient httpClient = EcNetHelper.getHttpClient();
    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> nvps = new ArrayList<>();
    Iterator<String> iter = this.params.keySet().iterator(); //this.params.keys();
    String key, value = "";
    while (iter.hasNext()) {
        key = iter.next(); //app.log(this.getClass().getSimpleName() + ".httpPost", "key: " + key);
        try {
            value = params.get(key);
        } catch (Exception e) {
            app.log(e);
        } //app.log(this.getClass().getSimpleName() + ".httpPost", "value: // " + value);
        nvps.add(new BasicNameValuePair(key, value));
    }
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        e.getMessage();
    }
    try {
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        inputStream = entity.getContent();
        if (EcConst.DEBUG)
            net.getCookieLog(this.getClass().getSimpleName());
    }
    //catch(ConnectTimeoutException e) { app.log(e); }
    //catch(ClientProtocolException e)   { app.log(e); }
    //catch(IOException e)   { app.log(e); }
    catch (Exception e) {
        app.log(e);
    }
    return inputStream;
}

From source file:biz.shadowservices.DegreesToolbox.HttpPoster.java

public HttpPoster(String uri, List<? extends NameValuePair> values) {
    httppost = new HttpPost(uri);
    try {/*  w w w  .j a va2 s.c  o m*/
        httppost.setEntity(new UrlEncodedFormEntity(values, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "Error:  Unsupported encoding exception on " + httppost.getURI());
    }
}

From source file:com.vintank.slack4j.webhook.SlackWebHook.java

public void send(Payload payload) throws IOException {
    HttpPost post = new HttpPost(url);

    try {// w  w w  .j a v a  2  s .c o m
        post.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Slack4j/1.0");
        post.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(AllClientPNames.CONNECTION_TIMEOUT, 5000);
        client.getParams().setParameter(AllClientPNames.SO_TIMEOUT, 5000);

        List<NameValuePair> nvps = new ArrayList<NameValuePair>(1);
        nvps.add(new BasicNameValuePair("payload", MAPPER.writeValueAsString(payload)));

        post.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

        client.execute(post);
    } finally {
        post.releaseConnection();
    }
}

From source file:br.cefetrj.sagitarii.teapot.comm.WebClient.java

public void doPost(String action, String parameter, String content) throws Exception {
    HttpClient httpclient = HttpClients.createDefault();
    HttpPost httppost = new HttpPost(gf.getHostURL() + "/" + action);

    // Request parameters and other properties.
    List<NameValuePair> params = new ArrayList<NameValuePair>(2);
    params.add(new BasicNameValuePair(parameter, content));
    //params.add(new BasicNameValuePair("param-2", "Hello!"));
    httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

    httpclient.execute(httppost);/*  ww w.j a  v a  2s.c om*/

}

From source file:cz.muni.fi.webmias.TeXConverter.java

/**
 * Converts TeX formula to MathML using LaTeXML through a web service.
 *
 * @param query String containing one or more keywords and TeX formulae
 * (formulae enclosed in $ or $$).//from   ww  w. j ava  2  s  .com
 * @return String containing formulae converted to MathML that replaced
 * original TeX forms. Non math tokens are connected at the end.
 */
public static String convertTexLatexML(String query) {
    query = query.replaceAll("\\$\\$", "\\$");
    if (query.matches(".*\\$.+\\$.*")) {
        try {
            HttpClient httpclient = HttpClients.createDefault();
            HttpPost httppost = new HttpPost(LATEX_TO_XHTML_CONVERSION_WS_URL);

            // Request parameters and other properties.
            List<NameValuePair> params = new ArrayList<>(1);
            params.add(new BasicNameValuePair("code", query));
            httppost.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8));

            // Execute and get the response.
            HttpResponse response = httpclient.execute(httppost);
            if (response.getStatusLine().getStatusCode() == 200) {
                HttpEntity resEntity = response.getEntity();
                if (resEntity != null) {
                    try (InputStream responseContents = resEntity.getContent()) {
                        DocumentBuilder dBuilder = MIaSUtils.prepareDocumentBuilder();
                        org.w3c.dom.Document doc = dBuilder.parse(responseContents);
                        NodeList ps = doc.getElementsByTagName("p");
                        String convertedMath = "";
                        for (int k = 0; k < ps.getLength(); k++) {
                            Node p = ps.item(k);
                            NodeList pContents = p.getChildNodes();
                            for (int j = 0; j < pContents.getLength(); j++) {
                                Node pContent = pContents.item(j);
                                if (pContent instanceof Text) {
                                    convertedMath += pContent.getNodeValue() + "\n";
                                } else {
                                    TransformerFactory transFactory = TransformerFactory.newInstance();
                                    Transformer transformer = transFactory.newTransformer();
                                    StringWriter buffer = new StringWriter();
                                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                                    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                                    transformer.transform(new DOMSource(pContent), new StreamResult(buffer));
                                    convertedMath += buffer.toString() + "\n";
                                }
                            }
                        }
                        return convertedMath;
                    }
                }
            }

        } catch (TransformerException | SAXException | ParserConfigurationException | IOException ex) {
            Logger.getLogger(ProcessServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return query;
}