我没有在文档中看到它,很高兴在这里查看:
HttpClient
是否使用网址行中的凭据管理HTTP授权(抢先或其他)?
例如: http://foo:bar@hostname/Hello/World
内联用户名foo
和密码bar
进行授权(实际身份验证,但只使用相同的命名法)。
基本上
HttpClient client = new HttpClient();
GetMethod get = new GetMethod("http://foo:bar@hostname/Hello/World");
VS:
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);
我没有尝试过它。
我错了吗?