use of org.apache.http.client.methods.HttpPost in project spring-framework by spring-projects.
the class HttpComponentsHttpInvokerRequestExecutorTests method customizeConnectionRequestTimeout.
@Test
public void customizeConnectionRequestTimeout() throws IOException {
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor();
executor.setConnectionRequestTimeout(7000);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
assertEquals(7000, httpPost.getConfig().getConnectionRequestTimeout());
}
use of org.apache.http.client.methods.HttpPost in project platform_frameworks_base by android.
the class BandwidthTestUtil method postFileToServer.
/**
* Post a given file for a given device and timestamp to the server.
* @param server {@link String} url of test server
* @param deviceId {@link String} device id that is uploading
* @param timestamp {@link String} timestamp
* @param file {@link File} to upload
* @return true if it succeeded
*/
public static boolean postFileToServer(String server, String deviceId, String timestamp, File file) {
try {
Log.d(LOG_TAG, "Uploading begining");
HttpClient httpClient = new DefaultHttpClient();
String uri = server;
if (!uri.endsWith("/")) {
uri += "/";
}
uri += "upload";
Log.d(LOG_TAG, "Upload url:" + uri);
HttpPost postRequest = new HttpPost(uri);
Part[] parts = { new StringPart("device_id", deviceId), new StringPart("timestamp", timestamp), new FilePart("file", file) };
MultipartEntity reqEntity = new MultipartEntity(parts, postRequest.getParams());
postRequest.setEntity(reqEntity);
HttpResponse res = httpClient.execute(postRequest);
res.getEntity().getContent().close();
} catch (IOException e) {
Log.e(LOG_TAG, "Could not upload file with error: " + e);
return false;
}
return true;
}
use of org.apache.http.client.methods.HttpPost in project androidquery by androidquery.
the class AbstractAjaxCallback method httpPost.
private void httpPost(String url, Map<String, Object> params, AjaxStatus status) throws ClientProtocolException, IOException {
AQUtility.debug("post", url);
HttpEntityEnclosingRequestBase req = new HttpPost(url);
httpEntity(url, req, params, status);
}
use of org.apache.http.client.methods.HttpPost in project jstorm by alibaba.
the class HttpClientService method excutePost.
protected String excutePost(String url, List<NameValuePair> nvps) throws Exception {
HttpClient httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
HttpResponse httpResponse = httpClient.execute(httpPost);
String response = parseResponse(url, httpResponse);
return response;
}
use of org.apache.http.client.methods.HttpPost in project jstorm by alibaba.
the class AlimonitorClient method httpPost.
private boolean httpPost(String url, String msg) {
boolean ret = false;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
CloseableHttpResponse response = null;
try {
HttpPost request = new HttpPost(url);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("name", monitorName));
nvps.add(new BasicNameValuePair("msg", msg));
request.setEntity(new UrlEncodedFormEntity(nvps));
response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
LOG.info(EntityUtils.toString(entity));
}
EntityUtils.consume(entity);
ret = true;
} catch (Exception e) {
LOG.error("Exception when sending http request to alimonitor", e);
} finally {
try {
if (response != null)
response.close();
httpClient.close();
} catch (Exception e) {
LOG.error("Exception when closing httpclient", e);
}
}
return ret;
}
Aggregations