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.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 ww w . j a v a2 s. 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 ww w.j a v a2 s .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. 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();//from www . j ava 2 s.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. 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 w w w . j a v 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. 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 w w w . j a v a 2 s . 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:org.aksw.simba.cetus.fox.FoxBasedTypeSearcher.java
public static void main(String[] args) throws UnsupportedCharsetException, ClientProtocolException, JSONException, IOException { Response response = Request.Post(FOX_SERVICE).addHeader("Content-type", "application/json") .addHeader("Accept-Charset", "UTF-8") .body(new StringEntity(new JSONObject().put("input", "Brian Banner is a fictional villain from the Marvel Comics Universe created by Bill Mantlo and Mike Mignola and first appearing in print in late 1985.") .put("type", "text").put("task", "ner").put("output", "JSON-LD").toString(), ContentType.APPLICATION_JSON)) .execute();//from ww w . j ava2 s .co m HttpResponse httpResponse = response.returnResponse(); HttpEntity entry = httpResponse.getEntity(); String content = IOUtils.toString(entry.getContent(), "UTF-8"); System.out.println(content); }
From source file:edu.xjtu.qxcamerabridge.JSONActionWrapper.java
public static JSONObject jsonrpc(String service, String methodName, List<Object> params) { JSONArray paramArray = new JSONArray(params); JSONObject requstjson = new JSONObject(); requstjson.put("method", methodName); requstjson.put("params", paramArray); requstjson.put("id", idGenerator()); requstjson.put("version", "1.0"); String requestjson = requstjson.toString(); System.out.println(requestjson); try {/* ww w .j ava 2 s. co m*/ Response reply = Request.Post(endPointURL(service)).bodyByteArray(requestjson.getBytes()).execute(); String replyContent = reply.returnContent().asString(); return new JSONObject(replyContent); } catch (IOException iOException) { iOException.printStackTrace(); } catch (JSONException jSONException) { jSONException.printStackTrace(); } return null; }
From source file:eu.anynet.java.util.HttpClient.java
/** * Create POST request// w ww .jav a 2 s .c o m * @param url The URL * @param form Formdata * @return The request */ public static Request Post(String url, Form form) { return defaults(Request.Post(url)).bodyForm(form.build()); }
From source file:org.apache.james.jmap.HttpJmapAuthentication.java
public static AccessToken authenticateJamesUser(URIBuilder uriBuilder, String username, String password) throws ClientProtocolException, IOException, URISyntaxException { String continuationToken = getContinuationToken(uriBuilder, username); Response response = Request.Post(uriBuilder.setPath("/authentication").build()) .bodyString("{\"token\": \"" + continuationToken + "\", \"method\": \"password\", \"password\": \"" + password + "\"}", ContentType.APPLICATION_JSON) .setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute(); return AccessToken.fromString(JsonPath.parse(response.returnContent().asString()).read("accessToken")); }