Search in sources :

Example 16 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method postUrlAsString.

/**
 * 通过POST方法请求url
 *
 * @param url
 * @param params
 */
public static void postUrlAsString(String url, Map<String, String> params, int reqTimeout, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getAsyncHttpClient(reqTimeout).preparePost(url);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.setBodyEncoding("utf-8");
        setPostParams(params, rb);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 17 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method uploadFile.

public static void uploadFile(String url, Map<String, String> params, byte[] bytes, String inputName, String fileName, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        setPostParams(params, rb);
        ByteArrayPart part = new ByteArrayPart(inputName, fileName, bytes, null, "utf-8");
        rb.addBodyPart(part);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Aggregations

BoundRequestBuilder (com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)15 IOException (java.io.IOException)12 Response (com.ning.http.client.Response)3 ExecutionException (java.util.concurrent.ExecutionException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)2 BoundRequestBuilder (org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)2 Response (org.apache.apex.shaded.ning19.com.ning.http.client.Response)2 Cookie (org.apache.apex.shaded.ning19.com.ning.http.client.cookie.Cookie)2 WebSocketUpgradeHandler (org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)1 Request (com.ning.http.client.Request)1 FilePart (com.ning.http.multipart.FilePart)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1