/** Set the request body as JSON. */ public HttpRequestBuilder withJsonContent(String content) { return withContent("application/json", content); }
/** Set the request body as JSON. */ public HttpRequestBuilder withJsonContent(String content) { return withContent("application/json", content); }
/** Set the request body. */ public HttpRequestBuilder withContent(String type, String content) { return withContent(type, content.getBytes(StandardCharsets.UTF_8)); }
/** Set the request body. */ public HttpRequestBuilder withContent(String type, String content) { return withContent(type, content.getBytes(StandardCharsets.UTF_8)); }
.withConnectTimeout((int) config.connectTimeout().toMillis()) .withReadTimeout((int) config.readTimeout().toMillis()) .withContent("application/x-jackson-smile", smileMapper.writeValueAsBytes(p)) .send(); } catch (IOException e) {
@Test public void okWithBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .addHeader("X-Status", "200") .withContent("text/plain", "foo") .send(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); }
@Test public void okWithCompressedBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .acceptGzip() .addHeader("X-Status", "200") .withContent("text/plain", "foo") .compress() .send() .decompress(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); } }