Delphi XE 5 - THTTPRIO - preemptive connection

552 Views Asked by At

I have a web service client created with DELPHI XE 5, i used THTTPRIO, imported wsdl and created the ".pas" files. The server of web service request a preemptive basic authentication (that work fine with SoapUI); I know how to make authentication with user and password of THTTPReqResp.

rio := THTTPRIO.Create(nil);
HTTPReqResp1 := THTTPReqResp.Create(rio);
HTTPReqResp1.UserName := sUserName;
HTTPReqResp1.Password := sPasswordEncrypted;

But I don't connect to the web service because I don't know ho to make preemptive and if it's possible in Delphi.

Can anyone help me ? :)

1

There are 1 best solutions below

0
Christopher Zaza On

I just found how It's possible to use "preemprive" connexion in DELPHI. You have to modify the OnBeforePost of your "rio.HTTPWebNode" like this :

var
rio  : THTTPRIO;
HTTPReqResp1: THTTPReqResp;
uselessObject: TUselessClass;
try
    rio := THTTPRIO.Create(nil);
    uselessObject := TUselessClass.Create();
    rio.HTTPWebNode.GetHTTPReqResp.OnBeforePost := 
    uselessObject.HTTPRIOHTTPWebNode1BeforePost;

With this procedure :

procedure TUselessClass.HTTPRIOHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
var
    auth,toEncode: string;
begin
    toEncode := Format('%s:%s',[sUserName,sPasswordEncrypted]);
    auth := 'Authorization: Basic ' + TIdEncoderMIME.EncodeString(toEncode);
    HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
end;