note 97029 modified in soapclient.soapclient by danbrown

From: Date: Mon, 29 Mar 2010 14:05:45 +0000
Subject: note 97029 modified in soapclient.soapclient by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167484@lists.php.net to get a copy of this message
To those fighting with NTLM authenticated proxy servers, here's a solution I'm using atm: <?php /** * A child of SoapClient with support for ntlm proxy authentication * * @author Meltir <meltir@meltir.com> * */ class NTLM_SoapClient extends SoapClient { public function __construct($wsdl, $options = array()) { if (empty($options['proxy_login']) || empty($options['proxy_password'])) throw new Exception('Login and password required for NTLM authentication!'); $this->proxy_login = $options['proxy_login']; $this->proxy_password = $options['proxy_password']; $this->proxy_host = (empty($options['proxy_host']) ? 'localhost' : $options['proxy_host']); $this->proxy_port = (empty($options['proxy_port']) ? 8080 : $options['proxy_port']); parent::__construct($wsdl, $options); } /** * Call a url using curl with ntlm auth * * @param string $url * @param string $data * @return string * @throws SoapFault on curl connection error */ protected function callCurl($url, $data) { $handle = curl_init(); curl_setopt($handle, CURLOPT_HEADER, false); curl_setopt($handle, CURLOPT_URL, $url); curl_setopt($handle, CURLOPT_FAILONERROR, true); curl_setopt($handle, CURLOPT_HTTPHEADER, Array("PHP SOAP-NTLM Client") ); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); curl_setopt($handle, CURLOPT_PROXYUSERPWD,$this->proxy_login.':'.$this->proxy_password); curl_setopt($handle, CURLOPT_PROXY, $this->proxy_host.':'.$this->proxy_port); curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM); $response = curl_exec($handle); if (empty($response)) { throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle)); } curl_close($handle); return $response; } public function __doRequest($request,$location,$action,$version,$one_way = 0) { return $this->callCurl($location,$request); } } ?> Requires curl and could be extended, but it works for my simple needs. --was-- To those fighting with NTLM authenticated proxy servers, here's a solution I'm using atm: /** * A child of SoapClient with support for ntlm proxy authentication * * @author Meltir <meltir@meltir.com> * */ class NTLM_SoapClient extends SoapClient { public function __construct($wsdl, $options = array()) { if (empty($options['proxy_login']) || empty($options['proxy_password'])) throw new Exception('Login and password required for NTLM authentication!'); $this->proxy_login = $options['proxy_login']; $this->proxy_password = $options['proxy_password']; $this->proxy_host = (empty($options['proxy_host']) ? 'localhost' : $options['proxy_host']); $this->proxy_port = (empty($options['proxy_port']) ? 8080 : $options['proxy_port']); parent::__construct($wsdl, $options); } /** * Call a url using curl with ntlm auth * * @param string $url * @param string $data * @return string * @throws SoapFault on curl connection error */ protected function callCurl($url, $data) { $handle = curl_init(); curl_setopt($handle, CURLOPT_HEADER, false); curl_setopt($handle, CURLOPT_URL, $url); curl_setopt($handle, CURLOPT_FAILONERROR, true); curl_setopt($handle, CURLOPT_HTTPHEADER, Array("PHP SOAP-NTLM Client") ); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); curl_setopt($handle, CURLOPT_PROXYUSERPWD,$this->proxy_login.':'.$this->proxy_password); curl_setopt($handle, CURLOPT_PROXY, $this->proxy_host.':'.$this->proxy_port); curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM); $response = curl_exec($handle); if (empty($response)) { throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle)); } curl_close($handle); return $response; } public function __doRequest($request,$location,$action,$version,$one_way = 0) { return $this->callCurl($location,$request); } } Requires curl and could be extended, but it works for my simple needs. http://php.net/manual/en/soapclient.soapclient.php

« previous php.notes (#167484) next »