我正在尝试使用Indy类进行HTTP身份验证。但是由于一些未知的原因,我在这一行中得到了一个访问冲突错误:IdHTTP1.Request.Authentication.Username :=用户名;
代码扩展是:
IdHTTP1:= TIdHttp.Create(Application);
IdHTTP1.ConnectTimeout:= 10000;
IdHTTP1.Request.Clear;
IdHTTP1.Request.BasicAuthentication:= true;
IdHTTP1.Request.Authentication.Username := Username;
IdHTTP1.Request.Authentication.Password := Password;
try
IdHTTP1.Get(PbxURL);
HttpCode := IdHTTP1.ResponseCode;
except
on E: EIdHTTPProtocolException do
HttpCode := IdHTTP1.ResponseCode;我正在使用Delphi2010,并且已经尝试过这样做:IdHTTP1.Request.Authentication.Username := 'admin';,但是没有解决这个问题……
发布于 2012-09-15 20:56:22
通过快速检查,当IdHTTP.Request.Authentication为真时,似乎不需要任何Request.BasicAuthentication (因此不需要创建)。您应该使用Request.UserName和Request.Password。
IdHTTP1:= TIdHttp.Create(Application);
IdHTTP1.ConnectTimeout:= 10000;
IdHTTP1.Request.Clear;
IdHTTP1.Request.BasicAuthentication:= true;
IdHTTP1.Request.UserName := UserName;
IdHTTP1.Request.Password := Password;发布于 2012-09-16 03:17:08
默认情况下,在发送请求和接收身份验证响应之前不会分配Request.Authentication对象,然后触发OnSelectAuthorization事件,以确定为后续请求分配对象的类类型。
可以分配Request.Authentication对象的唯一其他方法是,在发送请求之前在自己的代码中手动执行,比如您提前知道服务器使用哪种方案而不发送请求来动态地发现该方案。
https://stackoverflow.com/questions/12441508
复制相似问题