使用 Indy http (idHTTP1.Get) 从 Delphi 2005 升级到 2010 后出现授权问题
我正在从 Delphi 2005 升级到 Delphi 2010。 我遇到了这个问题:以下过程在 D2005 上运行良好,但在 D2010 上我总是得到结果:
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>
Your client does not have permission to get URL /axis-cgi/date.cgi from this server.
</BODY></HTML>
在该过程中,我尝试连接两次,因为在 D2005 上,有时我在第一次尝试时得到了未经授权的答案,然后我第二次就可以正常连接了。使用 D2010,我总是得到未经授权的答案。
Url = 'http://user:[电子邮件受保护]/axis -cgi/date.cgi?action=get'
function TViewCameraForm.HttpGet(idHTTP : TidHTTP; Url : AnsiString): AnsiString;
Var
Res : AnsiString;
Begin
idHTTP1.Disconnect;
try
Res := idHTTP1.Get(Url);
If Pos('Unauthorized', Res) > 0 Then
Res := idHTTP1.Get(Url);
Result := Res;
except
on E: EIdHTTPProtocolException do begin
Result := E.ErrorMessage
end;
on E: Exception do begin
Result := E.message;
end;
end;
End;
谢谢 山姆
I'm upgrading from Delphi 2005 to Delphi 2010.
I'm having this problem : the following procedure works well on D2005 but on D2010 I got always the result :
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>
Your client does not have permission to get URL /axis-cgi/date.cgi from this server.
</BODY></HTML>
On the procedure, I try to connect twice because on D2005, sometimes I got an Unauthorized answer at my first try, and then I can connect at the second time with no problem. With D2010 I always get the Unauthorized answer.
The Url = 'http://user:[email protected]/axis-cgi/date.cgi?action=get'
function TViewCameraForm.HttpGet(idHTTP : TidHTTP; Url : AnsiString): AnsiString;
Var
Res : AnsiString;
Begin
idHTTP1.Disconnect;
try
Res := idHTTP1.Get(Url);
If Pos('Unauthorized', Res) > 0 Then
Res := idHTTP1.Get(Url);
Result := Res;
except
on E: EIdHTTPProtocolException do begin
Result := E.ErrorMessage
end;
on E: Exception do begin
Result := E.message;
end;
end;
End;
Thanks
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试使用基本身份验证进行身份验证?
(顺便说一句,使用 user:pass@website 不符合 HTTP 规范)
Did you try to authenticate using Basic Auth?
(using user:pass@website does not conform to the HTTP specification btw)