Delphi 为什么我必须发送两个连续的HTTP Get请求才能进行身份验证?
这是我们的后续问题。我了解到,在请求中使用HTTP用户名/密码参数时,有两个不同的Delphi 为什么我必须发送两个连续的HTTP Get请求才能进行身份验证?,delphi,http,basic-authentication,indy,indy10,Delphi,Http,Basic Authentication,Indy,Indy10,这是我们的后续问题。我了解到,在请求中使用HTTP用户名/密码参数时,有两个不同的Get请求需要发送到服务器。第一次尝试不包括用户名/密码凭据,但如果身份验证失败,则会发送另一个包含这些凭据的相同请求 然而,当使用Indy的TIdHTTP时,它只发送一个请求,而未经授权则会失败。需要第二个相同的连续请求才能根据需要获得响应 我想知道,这是设计的,还是Indy的一个缺陷?这是因为使用了HTTP协商身份验证方法: (见图1) 如果你能找到更多信息 举个例子,如果SOAPUI与Exchange we
Get
请求需要发送到服务器。第一次尝试不包括用户名/密码凭据,但如果身份验证失败,则会发送另一个包含这些凭据的相同请求
然而,当使用Indy的TIdHTTP
时,它只发送一个请求,而未经授权
则会失败。需要第二个相同的连续请求才能根据需要获得响应
我想知道,这是设计的,还是Indy的一个缺陷?这是因为使用了HTTP协商身份验证方法:
(见图1)
如果你能找到更多信息
举个例子,如果SOAPUI与Exchange web服务建立经过身份验证的连接,我将看到以下HTTP:
1> >> "POST /ews/exchange.asmx HTTP/1.1[\r][\n]"
>> "Accept-Encoding: gzip,deflate[\r][\n]"
>> "SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/ResolveNames"[\r][\n]"
>> "Content-Type: text/xml; charset=utf-8[\r][\n]"
>> "Content-Length: 548[\r][\n]"
>> "Host: webmail.ttbv.nl[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
>> "[\r][\n]"
>> "<soapenv:Envelope [\n]"
[snip]
>> "</soapenv:Envelope>[\n]"
>> "[\n]"
1< << "HTTP/1.1 401 Unauthorized[\r][\n]"
<< "Cache-Control: private[\r][\n]"
<< "Server: Microsoft-IIS/7.5[\r][\n]"
<< "X-AspNet-Version: 2.0.50727[\r][\n]"
<< "Set-Cookie: exchangecookie=a29f10ca2a6d484ea276737e87d8e733; expires=Wed, 13-Nov-2013 10:47:33 GMT; path=/; HttpOnly[\r][\n]"
<< "WWW-Authenticate: Negotiate[\r][\n]"
<< "WWW-Authenticate: NTLM[\r][\n]"
<< "X-Powered-By: ASP.NET[\r][\n]"
<< "Date: Tue, 13 Nov 2012 10:47:33 GMT[\r][\n]"
<< "Content-Length: 0[\r][\n]"
<< "[\r][\n]"
2> >> "POST /ews/exchange.asmx HTTP/1.1[\r][\n]"
>> "Accept-Encoding: gzip,deflate[\r][\n]"
>> "SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/ResolveNames"[\r][\n]"
>> "Content-Type: text/xml; charset=utf-8[\r][\n]"
>> "Content-Length: 548[\r][\n]"
>> "Host: webmail.ttbv.nl[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
>> "Cookie: exchangecookie=a29f10ca2a6d484ea276737e87d8e733[\r][\n]"
>> "Cookie2: $Version=1[\r][\n]"
>> "Authorization: NTLM TlRMTVNTUAAB[snip]QgBWAA==[\r][\n]"
>> "[\r][\n]"
>> "<soapenv:Envelope [\n]"
[snip]
>> "</soapenv:Envelope>[\n]"
>> "[\n]"
2< << "HTTP/1.1 401 Unauthorized[\r][\n]"
<< "Server: Microsoft-IIS/7.5[\r][\n]"
<< "WWW-Authenticate: NTLM TlRMTVNTU[snip]AACAAAAFAAAAA==[\r][\n]"
<< "WWW-Authenticate: Negotiate[\r][\n]"
<< "X-Powered-By: ASP.NET[\r][\n]"
<< "Date: Tue, 13 Nov 2012 10:47:33 GMT[\r][\n]"
<< "Content-Length: 0[\r][\n]"
<< "[\r][\n]"
3> >> "POST /ews/exchange.asmx HTTP/1.1[\r][\n]"
>> "Accept-Encoding: gzip,deflate[\r][\n]"
>> "SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/ResolveNames"[\r][\n]"
>> "Content-Type: text/xml; charset=utf-8[\r][\n]"
>> "Content-Length: 548[\r][\n]"
>> "Host: webmail.ttbv.nl[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
>> "Cookie: exchangecookie=a29f10ca2a6d484ea276737e87d8e733[\r][\n]"
>> "Cookie2: $Version=1[\r][\n]"
>> "Authorization: NTLM TlRMTVNT[snip]AVABUADcANAA=[\r][\n]"
>> "[\r][\n]"
>> "<soapenv:Envelope [\n]"
[snip]
>> "</soapenv:Envelope>[\n]"
>> "[\n]"
3< << "HTTP/1.1 200 OK[\r][\n]"
<< "Cache-Control: private[\r][\n]"
<< "Transfer-Encoding: chunked[\r][\n]"
<< "Content-Type: text/xml; charset=utf-8[\r][\n]"
<< "Server: Microsoft-IIS/7.5[\r][\n]"
<< "X-EwsPerformanceData: RpcC=2;RpcL=0;LdapC=1;LdapL=0;[\r][\n]"
<< "X-AspNet-Version: 2.0.50727[\r][\n]"
<< "Persistent-Auth: true[\r][\n]"
<< "X-Powered-By: ASP.NET[\r][\n]"
<< "Date: Tue, 13 Nov 2012 10:47:33 GMT[\r][\n]"
<< "[\r][\n]"
<< "877[\r][\n]"
<< "<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
[snip]
<< "</s:Envelope>"
<< "[\r][\n]"
<< "0[\r][\n]"
<< "[\r][\n]"
1>>>“POST/ews/exchange.asmx HTTP/1.1[\r][\n]”
>>接受编码:gzip,解压缩[\r][\n]
>>“SOAPAction:”http://schemas.microsoft.com/exchange/services/2006/messages/ResolveNames“[\r][\n]”
>>“内容类型:text/xml;字符集=utf-8[\r][\n]”
>>“内容长度:548[\r][\n]”
>>“主机:webmail.ttbv.nl[\r][\n]”
>>“连接:保持活动状态[\r][\n]”
>>“用户代理:Apache HttpClient/4.1.1(java 1.5)[\r][\n]”
>>“[\r][\n]”
>>“您需要确保:
在TIdHTTP.HTTPOptions
属性中启用hoInProcessAuth
标志
有:
a、 分配的OnAuthorization
事件处理程序,用于将Authentication.UserName
和Authentication.Password
参数以及Handled
参数设置为True
b、 分配给TIdHTTP.Request.Password
属性的非空字符串
任何必要的IdAuthentication…
单元(如IdAuthenticationNTLM
或IdAuthenticationSSPI
),或IdAllAuthentications
子句中指定的IdAllAuthentications
单元
如果不满足这些条件,TIdHTTP
将不会尝试处理基于HTTP的身份验证。您是否只需要处理事件?请查看IdHttpInstance.Request.UserName&Passwordproperties@ComputerSaysNo是的,但是,TIdHTTP
设计用于处理此类情况并自动发送subsequent身份验证要求用户无需手动执行。[向Remy发送虚拟啤酒]这解决了所有问题,也回答了我之前的问题:-)特别是hoInProcessAuth
部分解决了所有问题