use of org.apache.http.client.methods.HttpPost in project nanohttpd by NanoHttpd.
the class TestNanoFileUpLoad method testPostWithMultipartFormUpload3.
@Test
public void testPostWithMultipartFormUpload3() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
String textFileName = UPLOAD_JAVA_FILE;
HttpPost post = new HttpPost("http://localhost:8192/uploadFile3");
executeUpload(httpclient, textFileName, post);
FileItem file = this.testServer.files.get("upfile").get(0);
Assert.assertEquals(file.getSize(), new File(textFileName).length());
}
use of org.apache.http.client.methods.HttpPost in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostRequestWithMultipartExtremEncodedParameters.
@Test
public void testPostRequestWithMultipartExtremEncodedParameters() throws Exception {
this.testServer.response = "testPostRequestWithMultipartEncodedParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/chin");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "sfsadfasdf", Charset.forName("UTF-8"));
reqEntity.addPart("specialString", new StringBody("拖拉图片到浏览器,可以实现预览功能", "text/plain", Charset.forName("UTF-8")));
reqEntity.addPart("gender", new StringBody("图片名称", Charset.forName("UTF-8")) {
@Override
public String getFilename() {
return "图片名称";
}
});
httppost.setEntity(reqEntity);
HttpResponse response = this.httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String responseBody = EntityUtils.toString(entity, "UTF-8");
assertEquals("POST:testPostRequestWithMultipartEncodedParameters-params=2;gender=图片名称;specialString=拖拉图片到浏览器,可以实现预览功能", responseBody);
}
use of org.apache.http.client.methods.HttpPost in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostWithNoParameters.
@Test
public void testPostWithNoParameters() throws Exception {
this.testServer.response = "testPostWithNoParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostWithNoParameters", responseBody);
}
use of org.apache.http.client.methods.HttpPost in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostRequestWithMultipartEncodedParameters.
@Test
public void testPostRequestWithMultipartEncodedParameters() throws Exception {
this.testServer.response = "testPostRequestWithMultipartEncodedParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("age", new StringBody("120"));
reqEntity.addPart("gender", new StringBody("Male"));
httppost.setEntity(reqEntity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostRequestWithMultipartEncodedParameters-params=2;age=120;gender=Male", responseBody);
}
use of org.apache.http.client.methods.HttpPost in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testPostRequestWithFormEncodedParameters.
@Test
public void testPostRequestWithFormEncodedParameters() throws Exception {
this.testServer.response = "testPostRequestWithFormEncodedParameters";
HttpPost httppost = new HttpPost("http://localhost:8192/");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("age", "120"));
postParameters.add(new BasicNameValuePair("gender", "Male"));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httppost, responseHandler);
assertEquals("POST:testPostRequestWithFormEncodedParameters-params=2;age=120;gender=Male", responseBody);
}
Aggregations