use of org.apache.http.client.methods.HttpPost in project android-uploader by nightscout.
the class RestV1UploaderTest method testCalRecord_Entity.
@Test
public void testCalRecord_Entity() throws Exception {
preferences.setCalibrationUploadEnabled(true);
restUploader.uploadCalRecords(Lists.newArrayList(mockCalRecord()));
HttpPost post = (HttpPost) captor.getValue();
String entity = CharStreams.toString(new InputStreamReader(post.getEntity().getContent()));
verifyCalRecord(new JSONObject(entity));
}
use of org.apache.http.client.methods.HttpPost in project ninja by ninjaframework.
the class NinjaTestBrowser method postJson.
public String postJson(String url, Object object) {
try {
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost(url);
StringEntity entity = new StringEntity(new ObjectMapper().writeValueAsString(object), "utf-8");
entity.setContentType("application/json; charset=utf-8");
post.setEntity(entity);
post.releaseConnection();
// Here we go!
return EntityUtils.toString(httpClient.execute(post).getEntity(), "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.http.client.methods.HttpPost in project ninja by ninjaframework.
the class NinjaTestBrowser method postXml.
public String postXml(String url, Object object) {
try {
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost(url);
StringEntity entity = new StringEntity(new XmlMapper().writeValueAsString(object), "utf-8");
entity.setContentType("application/xml; charset=utf-8");
post.setEntity(entity);
post.releaseConnection();
// Here we go!
return EntityUtils.toString(httpClient.execute(post).getEntity(), "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.http.client.methods.HttpPost in project ninja by ninjaframework.
the class NinjaTestBrowser method uploadFile.
public String uploadFile(String url, String paramName, File fileToUpload) {
String response = null;
try {
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
// For File parameters
entity.addPart(paramName, new FileBody((File) fileToUpload));
post.setEntity(entity);
// Here we go!
response = EntityUtils.toString(httpClient.execute(post).getEntity(), "UTF-8");
post.releaseConnection();
} catch (Exception e) {
throw new RuntimeException(e);
}
return response;
}
use of org.apache.http.client.methods.HttpPost in project openhab1-addons by openhab.
the class StreamClientImpl method createHttpRequest.
protected HttpUriRequest createHttpRequest(UpnpMessage upnpMessage, UpnpRequest upnpRequestOperation) throws MethodNotSupportedException {
switch(upnpRequestOperation.getMethod()) {
case GET:
return new HttpGet(upnpRequestOperation.getURI());
case SUBSCRIBE:
return new HttpGet(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.SUBSCRIBE.getHttpName();
}
};
case UNSUBSCRIBE:
return new HttpGet(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.UNSUBSCRIBE.getHttpName();
}
};
case POST:
HttpEntityEnclosingRequest post = new HttpPost(upnpRequestOperation.getURI());
post.setEntity(createHttpRequestEntity(upnpMessage));
// Fantastic API
return (HttpUriRequest) post;
case NOTIFY:
HttpEntityEnclosingRequest notify = new HttpPost(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.NOTIFY.getHttpName();
}
};
notify.setEntity(createHttpRequestEntity(upnpMessage));
// Fantastic API
return (HttpUriRequest) notify;
default:
throw new MethodNotSupportedException(upnpRequestOperation.getHttpMethodName());
}
}
Aggregations