[BAEL-18364] move spring-rest-*** articles - 1

This commit is contained in:
Sjmillington
2019-10-17 17:17:31 +01:00
parent db85c8f275
commit f1673ce653
20415 changed files with 1639515 additions and 0 deletions
@@ -0,0 +1,45 @@
package com.baeldung.okhttp;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class OkHttpHeaderLiveTest {
private static final String SAMPLE_URL = "http://www.github.com";
OkHttpClient client;
@Before
public void init() {
client = new OkHttpClient();
}
@Test
public void whenSetHeader_thenCorrect() throws IOException {
Request request = new Request.Builder().url(SAMPLE_URL).addHeader("Content-Type", "application/json").build();
Call call = client.newCall(request);
Response response = call.execute();
response.close();
}
@Test
public void whenSetDefaultHeader_thenCorrect() throws IOException {
OkHttpClient clientWithInterceptor = new OkHttpClient.Builder().addInterceptor(new DefaultContentTypeInterceptor("application/json")).build();
Request request = new Request.Builder().url(SAMPLE_URL).build();
Call call = clientWithInterceptor.newCall(request);
Response response = call.execute();
response.close();
}
}