user2417750
user2417750

Reputation: 41

How to add Authorization header to SOAP request with THTTPRIO in Delphi XE7?

I use THTTPRIO in Delphi XE7 to get data from a SOAP server. I try the request with SoapUI without a problem.

POST /ClientServices/ClientServPort.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "getUserList"
Authorization: Basic YjNm...Uo0Z1Y0cA==
Content-Length: 436
Host: eclienttest.abc.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/16.0.2)


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:en="http:/abc.com/eUserList/">
   <soapenv:Header/>
   <soapenv:Body>
     <en:getUserListRequest>
         <en:Role>AAA</en:Role>
     </en:getUserListRequest>
   </soapenv:Body>
</soapenv:Envelope>

On the Delphi side, I can't add Authorization: Basic YjNm...Uo0Z1Y0cA== to the request header. How can I do that?

Upvotes: 2

Views: 74

Answers (2)

user2417750
user2417750

Reputation: 41

Instead of THTTPRIO I used TidHttp with BasicAuth. I attached my request as StringStream to Post It worked.

Memo.Lines.Add('<soapenv:Envelope xmlns....') ;
Memo.Lines.Add('envelope/" xmlns:en="http:/abc.com/eUserList/">') ;
...

Postdata := TStringStream.Create;
PostData := TStringStream.Create(Memo.Text, TEncoding.UTF8);

myHttp.Request.BasicAuthentication := True;
myHttp.Request.Username := 'myUser' ;
myHttp.Request.Password := 'myPass' ;

myHttp.Request.CustomHeaders.Values['SOAPAction'] := 'getUserList';

myHttp.Post('PostAddres', PostData, ResponseData) ;

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 597916

Set the UserName and Password properties of the THTTPRIO.HTTPWebNode. They will be combined and base64-encoded into the Authorization header when the HTTP request is created.

Upvotes: 3

Related Questions