Indy (Delphi) Http客户端和摘要认证

5
我正在尝试与需要摘要认证的局域网(http://)服务器进行通信。
uses IdHttp, IdAuthenticationDigest;

...

begin
  IdHttp1 := TIdHttp.Create(nil);
  try
    IdHttp1.Request.Username := 'xxx';
    IdHttp1.Request.Password := 'xxx';

    Result := IdHttp1.Get(URL)
  finally
    idHttp1.Free;
  end;
end; 

不幸的是,当我从服务器获取IdHttp1.ResponseText时,我收到了HTTP/1.0 401未经授权。如果我输入用户名和密码,Firefox和Chrome都可以正常连接。

我使用最新的来自SVN和Delphi 7的Indy 10。

服务器(局域网上的192.168.1.10)的http标头:

Connecting...
Resolving hostname dm7020hd.
Connecting to 192.168.1.10.
Connected.
Server: webserver/1.0
Date: Thu, 31 Jan 2013 11:28:32 GMT
WWW-Authenticate: Digest algorithm="MD5", realm="Forbidden", qop="auth", opaque="7edfc2c756ad1f795651f15f88c32b25", nonce="d2ef913b753b3b6ad8878b34b93cfc5a"
Content-Type: text/html
Cache-Control: no-store, no-cache, must-revalidate
Expires: Sat, 10 Jan 2000 05:00:00 GMT
Content-Length: 15
Last-Modified: Thu, 31 Jan 2013 11:28:32 GMT
ETag: "753868328"
Connection: close
Disconnected

我已经搜索了很多关于这个问题的资料,显然很多人都在处理Indy身份验证方面遇到了麻烦(它根本就不起作用吗?)。

尝试包含这行代码 IdHttp1.Request.BasicAuthentication := False; - TLama
1个回答

7

您需要在TIdHTTP.HTTPOptions属性中启用hoInProcessAuth标志。默认情况下,它是禁用的。如果没有该标志,TIdHTTP.Get()将不会发送第二个HTTP请求以回复服务器的401响应中指定的摘要凭据。它将简单地退出并期望您处理401响应并根据需要发送新请求。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接