use of okhttp3.RequestBody in project retrofit by square.
the class RequestBuilderTest method multipartNullRemovesPart.
@Test
public void multipartNullRemovesPart() throws IOException {
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@Part("ping") String ping, @Part("fizz") String fizz) {
return null;
}
}
Request request = buildRequest(Example.class, "pong", null);
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
RequestBody body = request.body();
Buffer buffer = new Buffer();
body.writeTo(buffer);
String bodyString = buffer.readUtf8();
assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"ping\"").contains("\r\npong\r\n--");
}
use of okhttp3.RequestBody in project keywhiz by square.
the class KeywhizClient method httpPost.
private String httpPost(HttpUrl url, Object content) throws IOException {
RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(content));
Request request = new Request.Builder().url(url).post(body).addHeader(HttpHeaders.CONTENT_TYPE, JSON.toString()).build();
return makeCall(request);
}
use of okhttp3.RequestBody in project keywhiz by square.
the class AutomationClientResourceIntegrationTest method addClients.
@Test
public void addClients() throws Exception {
CreateClientRequest request = new CreateClientRequest("User1");
String requestJSON = mapper.writeValueAsString(request);
RequestBody body = RequestBody.create(KeywhizClient.JSON, requestJSON);
Request post = new Request.Builder().post(body).url(testUrl("/automation/clients")).addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
Response httpResponse = mutualSslClient.newCall(post).execute();
assertThat(httpResponse.code()).isEqualTo(200);
}
use of okhttp3.RequestBody in project keywhiz by square.
the class ClientResourceTest method modifyClient_notFound.
@Test
public void modifyClient_notFound() throws Exception {
ModifyClientRequestV2 request = ModifyClientRequestV2.forName("non-existent");
RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(request));
Request post = clientRequest("/automation/v2/clients/non-existent").post(body).build();
Response httpResponse = mutualSslClient.newCall(post).execute();
assertThat(httpResponse.code()).isEqualTo(404);
}
use of okhttp3.RequestBody in project keywhiz by square.
the class ClientResourceTest method create.
Response create(CreateClientRequestV2 request) throws IOException {
RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(request));
Request post = clientRequest("/automation/v2/clients").post(body).build();
return mutualSslClient.newCall(post).execute();
}
Aggregations