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, HttpResultCallback callback) {
try {
BoundRequestBuilder rb = getDefault().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);
}
}
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, File file, String inputName, String fileName, HttpResultCallback callback) {
try {
BoundRequestBuilder rb = getDefault().preparePost(url);
setPostParams(params, rb);
FilePart part = new FilePart(inputName, fileName, file);
rb.addBodyPart(part);
rb.execute(new AsynchHandler(callback));
} catch (IOException e) {
DB_LOGGER.error(e, 30);
}
}
use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.
the class AsyncHttpUtils method getUrlAsString.
/**
* 通过GET方法请求url
*
* @param url
* @param params
*/
public static void getUrlAsString(String url, Map<String, String> params, int reqTimeout, HttpResultCallback callback) {
if (StringUtils.isBlank(url)) {
return;
}
String gurl = getFullUrl(url, params, "utf-8");
try {
BoundRequestBuilder rb = getAsyncHttpClient(reqTimeout).prepareGet(gurl);
rb.setHeader("Accept-Encoding", "gzip,deflate");
rb.execute(new AsynchHandler(callback));
} catch (IOException e) {
DB_LOGGER.error(e, 30);
}
}
use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.
the class AsyncHttpUtils method postBodyAsString.
/**
* 通过POST方法请求url
*
* @param url
* @param body
*/
public static void postBodyAsString(String url, String body, HttpResultCallback callback) {
try {
BoundRequestBuilder rb = getDefault().preparePost(url);
rb.setHeader("Accept-Encoding", "gzip,deflate");
rb.setBodyEncoding("utf-8");
rb.setBody(body);
rb.execute(new AsynchHandler(callback));
} catch (IOException e) {
DB_LOGGER.error(e, 30);
}
}
use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project openhab1-addons by openhab.
the class PlexConnector method internalSendCommand.
private void internalSendCommand(String machineIdentifier, String url) throws IOException {
logger.debug("Calling url {}", url);
BoundRequestBuilder builder = client.prepareGet(url).setHeaders(getDefaultHeaders()).setHeader("X-Plex-Target-Client-Identifier", machineIdentifier);
builder.execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
if (response.getStatusCode() != 200) {
logger.error("Error while sending command to Plex: {}\r\n{}", response.getStatusText(), response.getResponseBody());
}
return response;
}
@Override
public void onThrowable(Throwable t) {
logger.error("Error sending command to Plex", t);
}
});
}
Aggregations