URLConnectionTest.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:GitHub 作者:
@Test public void doesNotAttemptAuthorization21Times() throws Exception {
  for (int i = 0; i < 21; i++) {
    server.enqueue(new MockResponse().setResponseCode(401));
  }

  String credential = Credentials.basic("jesse", "peanutbutter");
  urlFactory.setClient(urlFactory.client().newBuilder()
      .authenticator(new RecordingOkAuthenticator(credential))
      .build());

  connection = urlFactory.open(server.url("/").url());
  try {
    connection.getInputStream();
    fail();
  } catch (ProtocolException expected) {
    assertEquals(401, connection.getResponseCode());
    assertEquals("Too many follow-up requests: 21", expected.getMessage());
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号