SOAP message – Add authentication in http header


I have to send a SOAP message to a WebService that needs basic authentication in the http request, but I can’t find a way to do it.

After searching I found some solutions and workarounds, but none of them worked.

Here’s my code:

procedure TMyForm.HTTPRIOHTTPWebNode1BeforePost(
const HTTPReqResp: THTTPReqResp; Data: Pointer);
UserName: string;
PassWord: string;

UserName := ‘aaa’;
Password := ‘bbb’;

if not InternetSetOption(Data,
Length(UserName)) then
raise Exception(SysErrorMessage(GetLastError));

if not InternetSetOption(Data,
Length(Password)) then
raise Exception(SysErrorMessage(GetLastError));


I tried setting the username and password in the HTTPRIO.HTTPWebNode, but it ignores them, and it doesn’t rise the exceptions.
The webservice keeps telling me that credentials are missing.

I managed to do it in c#

protected override WebRequest GetWebRequest(Uri uri)

HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
Byte[] credentialBuffer = new UTF8Encoding().GetBytes(“aaa:bbb”);
request.Headers.Add(“Authorization”, string.Format(“Basic {0}”, Convert.ToBase64String(credentialBuffer)));
return request;


but I can’t find a way to do it in delphi.

Am I missing something or I’m doing it wrong?

I use DelphiXE8 with Firemonkey.

Comments are closed.