如何连接到具有基本身份验证的网站?我正在使用http组件。我看到某个地方,?username=&password=
被使用,但它不适合我。如何使用基本身份验证从网站检索数据?
感谢Ralf的回答,我发现我忘了在网址中添加authMethod
。这里是解决方案:
http://localhost/?authMethod=Basic&authUsername=username&authPassword=password
如何连接到具有基本身份验证的网站?我正在使用http组件。我看到某个地方,?username=&password=
被使用,但它不适合我。如何使用基本身份验证从网站检索数据?
感谢Ralf的回答,我发现我忘了在网址中添加authMethod
。这里是解决方案:
http://localhost/?authMethod=Basic&authUsername=username&authPassword=password
望着http compoment文档下面应该工作:
http://...?authMethod=Basic&authUsername=...&authPassword=...
注意使用基本身份验证不使用SSL/TLS的安全隐患。
它的工作原理。我忘了添加authMethod = Basic。谢谢 :) – aphex
我建议你阅读this页往下看的头“身份验证和代理服务器”。在那里你可以找到以下记录 - authMethod
,authUsername
和authPassword
。要使用它,我会做这样的事情
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);
由于大多数网站使用POST方法登录..您的查询字符串方法可能无法正常工作。 – Sorter
@DeepakMishra POST认证与HTTP BASIC认证不同。这具有特定的技术含义。 –