diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java index cbe5ff885c..be3f5d67c9 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java @@ -49,7 +49,13 @@ public class OkHttpPostingLiveTest { public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException { final String postBody = "test post"; - final Request request = new Request.Builder().url(URL_SECURED_BY_BASIC_AUTHENTICATION).addHeader("Authorization", Credentials.basic("test", "test")).post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), postBody)).build(); + client = new OkHttpClient(); + + final Request request = new Request.Builder() + .url(URL_SECURED_BY_BASIC_AUTHENTICATION) + .addHeader("Authorization", Credentials.basic("test", "test")) + .post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), "test post")) + .build(); final Call call = client.newCall(request); final Response response = call.execute(); @@ -61,8 +67,9 @@ public class OkHttpPostingLiveTest { public void whenPostJson_thenCorrect() throws IOException { final String json = "{\"id\":1,\"name\":\"John\"}"; - final RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); + client = new OkHttpClient(); + final RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"id\":1,\"name\":\"John\"}"); final Request request = new Request.Builder().url(BASE_URL + "/users/detail").post(body).build(); final Call call = client.newCall(request);