如何使用基本身份验证从网站检索数据?

时间:2013-11-28 17:08:40

标签: java apache-camel

如何使用基本身份验证连接到网站?我正在使用http组件。我在某处看到,?username=&password=被使用,但它对我不起作用。

感谢Ralf的回答,我发现忘记将authMethod添加到网址中。这是解决方案:

http://localhost/?authMethod=Basic&authUsername=username&authPassword=password

2 个答案:

答案 0 :(得分:0)

我建议您阅读this页面并查看标题“身份验证和代理”。在那里,您可能会发现以下文档:authMethodauthUsernameauthPassword。要使用它,我会做这样的事情

String authUsername = "MyUser";
String authPassword = "MyPass";
HttpComponent http = new HttpComponent();

HttpConfiguration config = http.getHttpConfiguration();
config.setAuthMethod(AuthMethod.Basic);
config.setAuthUsername(authUsername);
config.setAuthPassword(authPassword);
http.setHttpConfiguration(config);

答案 1 :(得分:0)

查看http compoment文档,以下内容应该有效:

http://...?authMethod=Basic&authUsername=...&authPassword=...

请注意使用没有SSL / TLS的基本身份验证的安全隐患。