Example usage for org.apache.http.client.fluent Form Form

List of usage examples for org.apache.http.client.fluent Form Form

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Form Form.

Prototype

Form() 

Source Link

Usage

From source file:com.ykun.commons.utils.http.HttpClientTest.java

public static void main(String[] args) throws Exception {

    System.out.println(HttpClientUtils.get("http://www.weather.com.cn/data/sk/101010100.html"));

    Map<String, String> params = new HashMap<String, String>();
    params.put("gameID", "1000001");
    params.put("accountID", "helloworld2");
    System.out.println(HttpClientUtils.post("http://115.159.156.171/home/main", params));

    System.out.println(HttpClientUtils.execute(Request.Post("http://115.159.156.171/home/main")
            .bodyForm(Form.form().add("gameID", "1000001").add("accountID", "helloworld2").build())));

}

From source file:interoperabilite.webservice.fluent.FluentQuickStart.java

public static void main(String[] args) throws Exception {
    // The fluent API relieves the user from having to deal with manual
    // deallocation of system resources at the cost of having to buffer
    // response content in memory in some cases.

    Request.Get("http://targethost/homepage").execute().returnContent();
    Request.Post("http://targethost/login")
            .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()).execute()
            .returnContent();//from www  . ja va2s.  c  o m
}

From source file:interoperabilite.webservice.fluent.FluentRequests.java

public static void main(String[] args) throws Exception {
    // Execute a GET with timeout settings and return response content as String.
    Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000).execute().returnContent()
            .asString();/*from w  ww .j a  v a 2s  .  c om*/

    // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1,
    // containing a request body as String and return response content as byte array.
    Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1)
            .bodyString("Important stuff", ContentType.DEFAULT_TEXT).execute().returnContent().asBytes();

    // Execute a POST with a custom header through the proxy containing a request body
    // as an HTML form and save the result to the file
    Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff")
            .viaProxy(new HttpHost("myproxy", 8080))
            .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()).execute()
            .saveContent(new File("result.dump"));
}

From source file:interoperabilite.webservice.fluent.FluentExecutor.java

public static void main(String[] args) throws Exception {
    Executor executor = Executor.newInstance().auth(new HttpHost("somehost"), "username", "password")
            .auth(new HttpHost("myproxy", 8080), "username", "password")
            .authPreemptive(new HttpHost("myproxy", 8080));

    // Execute a GET with timeout settings and return response content as String.
    executor.execute(Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000)).returnContent()
            .asString();//w  w  w .j a v a 2  s.com

    // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1,
    // containing a request body as String and return response content as byte array.
    executor.execute(Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1)
            .bodyString("Important stuff", ContentType.DEFAULT_TEXT)).returnContent().asBytes();

    // Execute a POST with a custom header through the proxy containing a request body
    // as an HTML form and save the result to the file
    executor.execute(Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff")
            .viaProxy(new HttpHost("myproxy", 8080))
            .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()))
            .saveContent(new File("result.dump"));
}

From source file:io.aos.protocol.http.httpcommon.FluentRequests.java

public static void main(String... args) throws Exception {
    // Execute a GET with timeout settings and return response content as String.
    Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000).execute().returnContent()
            .asString();//from   www . ja  v a 2  s.com

    // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1,
    // containing a request body as String and return response content as byte array.
    Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1)
            .bodyString("Important stuff", ContentType.DEFAULT_TEXT).execute().returnContent().asBytes();

    // Execute a POST with a custom header through the proxy containing a request body
    // as an HTML form and save the result to the file
    Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff")
            .viaProxy(new HttpHost("myproxy", 8080))
            .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()).execute()
            .saveContent(new File("result.dump"));
}

From source file:io.aos.protocol.http.httpcommon.FluentExecutor.java

public static void main(String... args) throws Exception {
    Executor executor = Executor.newInstance().auth(new HttpHost("somehost"), "username", "password")
            .auth(new HttpHost("myproxy", 8080), "username", "password")
            .authPreemptive(new HttpHost("myproxy", 8080));

    // Execute a GET with timeout settings and return response content as String.
    executor.execute(Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000)).returnContent()
            .asString();//from  www. jav a 2s  .c o m

    // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1,
    // containing a request body as String and return response content as byte array.
    executor.execute(Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1)
            .bodyString("Important stuff", ContentType.DEFAULT_TEXT)).returnContent().asBytes();

    // Execute a POST with a custom header through the proxy containing a request body
    // as an HTML form and save the result to the file
    executor.execute(Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff")
            .viaProxy(new HttpHost("myproxy", 8080))
            .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()))
            .saveContent(new File("result.dump"));
}

From source file:com.enitalk.controllers.paypal.BasicPaypal.java

public String authPaypal() {
    String tt = null;//from   w w  w  .  j ava2 s .  c o m
    try {
        tt = redis.opsForValue().get("paypal");
        if (StringUtils.isNotBlank(tt)) {
            return tt;
        }

        String url = env.getProperty("paypal.auth");
        String auth = env.getProperty("paypal.client") + ":" + env.getProperty("paypal.secret");
        String encoded = java.util.Base64.getEncoder().encodeToString(auth.getBytes());

        logger.info("Posting paypal auth to {} client {}", url, encoded);
        byte[] json = Request.Post(url).addHeader("Authorization", "Basic " + encoded)
                .bodyForm(Form.form().add("grant_type", "client_credentials").build()).execute().returnContent()
                .asBytes();

        JsonNode tree = jackson.readTree(json);
        tt = tree.path("access_token").asText();
        long duration = tree.path("expires_in").asLong();

        redis.opsForValue().set("paypal", tt, duration - 5, TimeUnit.SECONDS);

    } catch (Exception ex) {
        logger.info("Error auth Paypal {}", ExceptionUtils.getFullStackTrace(ex));
    }
    return tt;
}

From source file:eu.anynet.java.uax.UaxApi.java

public UaxResult shortUrl(String url, String userdef) {
    if (this.apikey == null || this.apikey.equals("fillmeout")) {
        this.apikey = "fillmeout";
        this.serialize();
        return null;
    }/*ww  w . j a  va2  s .c o  m*/

    try {
        Form form = Form.form().add("api_key", this.apikey).add("url", url).add("userdef", userdef);

        JSONObject result = HttpClient.toJsonObject(HttpClient.Post("http://krz.link/~api/add", form));
        boolean success = result.get("success").toString().equals("true");

        if (success) {
            return new UaxResult(result);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.ctrip.infosec.rule.resource.Counter.java

/**
 * ???//  www  .  ja  v a2s . co  m
 *
 * @param bizNo ?
 * @return
 */
public static GetDataFieldListResponse datafieldList(String bizNo) {
    check();
    GetDataFieldListResponse response = null;
    try {
        String responseTxt = Request.Post(urlPrefix + "/rest/configs/datafieldList")
                .bodyForm(Form.form().add("bizNo", bizNo).build(), Charset.forName("UTF-8")).execute()
                .returnContent().asString();
        response = JSON.parseObject(responseTxt, GetDataFieldListResponse.class);
    } catch (Exception ex) {
        logger.error(Contexts.getLogPrefix() + "invoke Counter.datafieldList fault.", ex);
        response = new GetDataFieldListResponse();
        response.setErrorCode(ErrorCode.EXCEPTION.getCode());
        response.setErrorMessage(ex.getMessage());
    }
    return response;
}

From source file:hulop.cm.util.LogHelper.java

public boolean saveLog(String clientId, JSONObject log) throws Exception {
    if (mApiKey == null) {
        return false;
    }// w  ww  .j ava2s  .c  om
    JSONObject data = new JSONObject();
    data.put("event", "conversation");
    data.put("client", clientId);
    data.put("timestamp", System.currentTimeMillis());
    data.put("log", log);
    Request request = Request.Post(new URI(mEndpoint)).bodyForm(Form.form().add("action", "insert")
            .add("auditor_api_key", mApiKey).add("data", new JSONArray().put(data).toString()).build());
    HttpResponse response = request.execute().returnResponse();
    return response.getStatusLine().getStatusCode() == 200;
}