Authentication IdHTTP Access Violation

I am trying to perform HTTP authentication using the Indy HTTP class. But for some unknown reason, I get an access violation error on this line: IdHTTP1.Request.Authentication.Username: = Username

Code Extension:

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; 

I am using Delphi 2010 and am already trying to do something like: IdHTTP1.Request.Authentication.Username: = 'admin'; but did not solve the problem ...

+4
source share
2 answers

With a quick check, it seems that there is no IdHTTP.Request.Authentication needed (and therefore no one is created) when the Request.BasicAuthentication value Request.BasicAuthentication true. Instead, you should use Request.UserName and Request.Password .

 IdHTTP1:= TIdHttp.Create(Application); IdHTTP1.ConnectTimeout:= 10000; IdHTTP1.Request.Clear; IdHTTP1.Request.BasicAuthentication:= true; IdHTTP1.Request.UserName := UserName; IdHTTP1.Request.Password := Password; 
+14
source

By default, the Request.Authentication object Request.Authentication not allocated until the request has been sent and the authentication response has been received, then the OnSelectAuthorization event will be OnSelectAuthorization to determine what type of class will be allocated for the object for subsequent requests.

The only other way that the Request.Authentication object can be allocated is to manually execute it in your own code before sending the request, for example, if you know in advance which auth scheme the server should use without sending a request for detection that is dynamic.

+2
source

Source: https://habr.com/ru/post/1434404/


All Articles