Delphi THTTPRio how to use authentication proxy

I used the WSDL importer with Delphi XE2, and it generated a routine that looks like this, with the exception of three comments in which I am trying to use a proxy server.

function GetIXYZService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IXYZService; const defWSDL = 'https://server/XYZService.svc?wsdl'; defURL = 'https://server/XYZService.svc'; defSvc = 'Company.XYZ.Services.XYZService'; defPrt = 'BasicHttpBinding_IXYZService'; var RIO: THTTPRIO; begin Result := nil; if (Addr = '') then begin if UseWSDL then Addr := defWSDL else Addr := defURL; end; if HTTPRIO = nil then RIO := THTTPRIO.Create(nil) else RIO := HTTPRIO; try // RIO.HTTPWebNode.Proxy := 'server_ip:port'; // RIO.HTTPWebNode.Username := 'username'; // RIO.HTTPWebNode.Password := 'password'; Result := (RIO as ISSOService); if UseWSDL then begin RIO.WSDLLocation := Addr; RIO.Service := defSvc; RIO.Port := defPrt; end else RIO.URL := Addr; finally if (Result = nil) and (HTTPRIO = nil) then RIO.Free; end; end; 

I need to access the service through an authentication proxy. I added 3 lines shown above, and when I uncomment them, I cannot connect. Help for THTTPRio states ...

If you need to use a proxy server or require an authentication server, use the properties of the THTTPReqResp object, which is the value of the HTTPWebNode property to provide the necessary information.

I did this, but when I try to use my service, an ESOAPHTTPException is thrown with a message ...

 Unauthorized (407) - 'https://server/XYZService.svc' 

I stumbled upon this post which says to set proxy settings after installing WSDLLocation, service and port, which I tried without success.

http://www.delphigroups.info/2/10/555621.html

I also do not build with USE_INDY. My service uses SSL, so I use WinInet.

I am not sure what is wrong with this approach, so any help is appreciated.

Thanks Michael

+7
source share
1 answer

According to this , there are two ways to set proxy authorization for wininet. I did not see HTTP_STATUS_PROXY_AUTH_REQ in the source code of Soap.SOAPHTTPTrans, so you probably have to write your own handling of this error. To do this, install the THTTPReqResp.OnWinInetError handler and process the HTTP_STATUS_PROXY_AUTH_REQ error code.

Or you can try to catch OnBeforePost from THTTPReqResp and call HttpAddRequestHeaders with a base64 login password and password. Hope this helps.

+2
source

All Articles