3

我没有在文档中看到它,很高兴在这里查看:

是否HttpClient使用 URL 行中的凭据管理 HTTP 授权(抢占式或其他方式)?

例如: http://foo:bar@hostname/Hello/World用于授权的内联用户名foo和密码bar(实际上是身份验证,但只是使用相同的命名法)。

基本上:

HttpClient client = new HttpClient();
GetMethod get = new GetMethod("http://foo:bar@hostname/Hello/World");

与:

HttpClient client = new HttpClient();
client.getState().setCredentials(
          new AuthScope( /* stuff */ );
        , new UsernamePasswordCredentials("foo","bar");
);
GetMethod get = new GetMethod("http://foo:bar@hostname/Hello/World");
get.setDoAuthentication(true);

我试过了,不高兴。
我有什么问题吗?

4

0 回答 0