use of org.apache.http.client.methods.HttpPost in project nanohttpd by NanoHttpd.
the class TestNanolets method doSomeBasicMethodTest.
@Test
public void doSomeBasicMethodTest() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost:9090/user/blabla");
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: GET<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
HttpPost httppost = new HttpPost("http://localhost:9090/user/blabla");
response = httpclient.execute(httppost);
entity = response.getEntity();
string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: POST<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
HttpPut httpgput = new HttpPut("http://localhost:9090/user/blabla");
response = httpclient.execute(httpgput);
entity = response.getEntity();
string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: PUT<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
HttpDelete httpdelete = new HttpDelete("http://localhost:9090/user/blabla");
response = httpclient.execute(httpdelete);
entity = response.getEntity();
string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: DELETE<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
}
use of org.apache.http.client.methods.HttpPost in project OpenAttestation by OpenAttestation.
the class ApacheHttpClient method post.
public ApiResponse post(String requestURL, ApiRequest message) throws IOException, SignatureException {
log.debug("POST url: {}", requestURL);
log.debug("POST content: {}", message == null ? "(empty)" : message.content);
HttpPost request = new HttpPost(requestURL);
if (message != null && message.content != null) {
request.setEntity(new StringEntity(message.content, ContentType.create(message.contentType.toString(), "UTF-8")));
}
HttpResponse httpResponse = httpClient.execute(request);
ApiResponse apiResponse = readResponse(httpResponse);
request.releaseConnection();
return apiResponse;
}
use of org.apache.http.client.methods.HttpPost in project openkit-android by OpenKit.
the class AsyncHttpClient method post.
/**
* Perform a HTTP POST request and track the Android Context which initiated
* the request. Set headers only for this request
*
* @param context the Android Context which initiated the request.
* @param url the URL to send the request to.
* @param headers set headers only for this request
* @param entity a raw {@link HttpEntity} to send with the request, for
* example, use this to send string/json/xml payloads to a server by
* passing a {@link org.apache.http.entity.StringEntity}.
* @param contentType the content type of the payload you are sending, for
* example application/json if sending a json payload.
* @param responseHandler the response handler instance that should handle
* the response.
*/
public void post(Context context, String url, Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPost(url), entity);
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
}
use of org.apache.http.client.methods.HttpPost in project openkit-android by OpenKit.
the class AsyncHttpClient method post.
/**
* Perform a HTTP POST request and track the Android Context which initiated
* the request. Set headers only for this request
*
* @param context the Android Context which initiated the request.
* @param url the URL to send the request to.
* @param headers set headers only for this request
* @param params additional POST parameters to send with the request.
* @param contentType the content type of the payload you are sending, for
* example application/json if sending a json payload.
* @param responseHandler the response handler instance that should handle
* the response.
*/
public void post(Context context, String url, Header[] headers, RequestParams params, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = new HttpPost(url);
if (params != null)
request.setEntity(paramsToEntity(params));
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
}
use of org.apache.http.client.methods.HttpPost in project OpenMEAP by OpenMEAP.
the class HttpRequestExecuterImpl method postContent.
public HttpResponse postContent(String url, String content, String contentType) throws HttpRequestException {
try {
StringEntity stringEntity = new StringEntity(content, FormConstants.CHAR_ENC_DEFAULT);
stringEntity.setContentType(contentType);
HttpPost httppost = new HttpPost(url);
httppost.setHeader(FormConstants.CONTENT_TYPE, contentType);
httppost.setEntity(stringEntity);
return execute(httppost);
} catch (Exception e) {
throw new HttpRequestException(e);
}
}
Aggregations