本文整理汇总了Java中okhttp3.logging.HttpLoggingInterceptor.Level类的典型用法代码示例。如果您正苦于以下问题:Java Level类的具体用法?Java Level怎么用?Java Level使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Level类属于okhttp3.logging.HttpLoggingInterceptor包,在下文中一共展示了Level类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: basicGet
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicGet() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
client.newCall(request().build()).execute();
applicationLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例2: basicPost
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicPost() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
client.newCall(request().post(RequestBody.create(PLAIN, "Hi?")).build()).execute();
applicationLogs
.assertLogEqual("--> POST " + url + " http/1.1 (3-byte body)")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> POST " + url + " http/1.1 (3-byte body)")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例3: basicResponseBody
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicResponseBody() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse()
.setBody("Hello!")
.setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 6-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 6-byte body\\)")
.assertNoMoreLogs();
}
示例4: basicChunkedResponseBody
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicChunkedResponseBody() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse()
.setChunkedBody("Hello!", 2)
.setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)")
.assertNoMoreLogs();
}
示例5: connectFail
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void connectFail() throws IOException {
setLevel(Level.BASIC);
client = new OkHttpClient.Builder()
.dns(new Dns() {
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException {
throw new UnknownHostException("reason");
}
})
.addInterceptor(applicationInterceptor)
.build();
try {
client.newCall(request().build()).execute();
fail();
} catch (UnknownHostException expected) {
}
applicationLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogEqual("<-- HTTP FAILED: java.net.UnknownHostException: reason")
.assertNoMoreLogs();
}
示例6: basicGet
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicGet() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
client.newCall(request().build()).execute();
applicationLogs
.assertLogEqual("--> GET " + url)
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例7: basicPost
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicPost() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
client.newCall(request().post(RequestBody.create(PLAIN, "Hi?")).build()).execute();
applicationLogs
.assertLogEqual("--> POST " + url + " (3-byte body)")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> POST " + url + " http/1.1 (3-byte body)")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例8: basicResponseBody
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicResponseBody() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse()
.setBody("Hello!")
.setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs
.assertLogEqual("--> GET " + url)
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 6-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 6-byte body\\)")
.assertNoMoreLogs();
}
示例9: basicChunkedResponseBody
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicChunkedResponseBody() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse()
.setChunkedBody("Hello!", 2)
.setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs
.assertLogEqual("--> GET " + url)
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " http/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)")
.assertNoMoreLogs();
}
示例10: connectFail
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void connectFail() throws IOException {
setLevel(Level.BASIC);
client = new OkHttpClient.Builder()
.dns(new Dns() {
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException {
throw new UnknownHostException("reason");
}
})
.addInterceptor(applicationInterceptor)
.build();
try {
client.newCall(request().build()).execute();
fail();
} catch (UnknownHostException expected) {
}
applicationLogs
.assertLogEqual("--> GET " + url)
.assertLogEqual("<-- HTTP FAILED: java.net.UnknownHostException: reason")
.assertNoMoreLogs();
}
示例11: http2
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void http2() throws Exception {
server.useHttps(sslClient.socketFactory, false);
url = server.url("/");
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
Response response = client.newCall(request().build()).execute();
assumeThat(response.protocol(), equalTo(Protocol.HTTP_2));
applicationLogs
.assertLogEqual("--> GET " + url)
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " h2")
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例12: getHeader
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
public static Builder getHeader(String userName, String password) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(Level.BASIC);
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(userName, password);
if (credential.equals(response.request().header("Authorization"))) {
try {
FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
} catch (IntegrationException e) {
throw new IOException(e);
}
return null;
}
return response.request().newBuilder().header("Authorization", credential).build();
}
});
okBuilder.addInterceptor(logging);
return okBuilder;
}
示例13: basicGet
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicGet() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
client.newCall(request().build()).execute();
applicationLogs
.assertLogEqual("--> GET " + url + " HTTP/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " HTTP/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例14: basicPost
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicPost() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse());
client.newCall(request().post(RequestBody.create(PLAIN, "Hi?")).build()).execute();
applicationLogs
.assertLogEqual("--> POST " + url + " HTTP/1.1 (3-byte body)")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> POST " + url + " HTTP/1.1 (3-byte body)")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}
示例15: basicResponseBody
import okhttp3.logging.HttpLoggingInterceptor.Level; //导入依赖的package包/类
@Test public void basicResponseBody() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse()
.setBody("Hello!")
.setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs
.assertLogEqual("--> GET " + url + " HTTP/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 6-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " HTTP/1.1")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 6-byte body\\)")
.assertNoMoreLogs();
}