note 97029 added to soapclient.soapclient
| From: | meltir at meltir dot com | Date: | Mon, 29 Mar 2010 13:59:48 +0000 |
| Subject: | note 97029 added to soapclient.soapclient | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167483@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:
/**
* 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.
----
Server IP: 92.48.74.199
Probable Submitter: 86.54.83.147
----
Manual Page -- http://www.php.net/manual/en/soapclient.soapclient.php
Edit -- https://master.php.net/note/edit/97029
Del: integrated -- https://master.php.net/note/delete/97029/integrated
Del: useless -- https://master.php.net/note/delete/97029/useless
Del: bad code -- https://master.php.net/note/delete/97029/bad+code
Del: spam -- https://master.php.net/note/delete/97029/spam
Del: non-english -- https://master.php.net/note/delete/97029/non-english
Del: in docs -- https://master.php.net/note/delete/97029/in+docs
Del: other reasons-- https://master.php.net/note/delete/97029
Reject -- https://master.php.net/note/reject/97029
Search -- https://master.php.net/manage/user-notes.php