use of org.asynchttpclient.request.body.multipart.ByteArrayPart in project async-http-client by AsyncHttpClient.
the class SimpleAsyncHttpClientTest method testMultiPartPost.
@Test(groups = "standalone")
public void testMultiPartPost() throws Exception {
try (SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/multipart").build()) {
Response response = client.post(new ByteArrayPart("baPart", "testMultiPart".getBytes(UTF_8), "application/test", UTF_8, "fileName")).get();
String body = response.getResponseBody();
String contentType = response.getHeader("X-Content-Type");
assertTrue(contentType.contains("multipart/form-data"));
String boundary = contentType.substring(contentType.lastIndexOf("=") + 1);
assertTrue(body.startsWith("--" + boundary));
assertTrue(body.trim().endsWith("--" + boundary + "--"));
assertTrue(body.contains("Content-Disposition:"));
assertTrue(body.contains("Content-Type: application/test"));
assertTrue(body.contains("name=\"baPart"));
assertTrue(body.contains("filename=\"fileName"));
}
}
use of org.asynchttpclient.request.body.multipart.ByteArrayPart in project async-http-client by AsyncHttpClient.
the class SimpleAsyncHttpClientTest method testMultiPartPut.
@Test(groups = "standalone")
public void testMultiPartPut() throws Exception {
try (SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/multipart").build()) {
Response response = client.put(new ByteArrayPart("baPart", "testMultiPart".getBytes(UTF_8), "application/test", UTF_8, "fileName")).get();
String body = response.getResponseBody();
String contentType = response.getHeader("X-Content-Type");
assertTrue(contentType.contains("multipart/form-data"));
String boundary = contentType.substring(contentType.lastIndexOf("=") + 1);
assertTrue(body.startsWith("--" + boundary));
assertTrue(body.trim().endsWith("--" + boundary + "--"));
assertTrue(body.contains("Content-Disposition:"));
assertTrue(body.contains("Content-Type: application/test"));
assertTrue(body.contains("name=\"baPart"));
assertTrue(body.contains("filename=\"fileName"));
}
}
Aggregations