note 101503 added to soapclient.soapclient

From: Date: Tue, 21 Dec 2010 14:58:22 +0000
Subject: note 101503 added to soapclient.soapclient
Groups: php.notes 
Request: Send a blank email to php-notes+get-175096@lists.php.net to get a copy of this message
I'm experiencing the same problems when trying to load a WDSL fiel which is protected by basic http authentication, since the parameters login and password are just used for the request but not when reading the wdsl file. I just use the following workaround by downloading the xml file to a non-protected location on my server. Please notice that this doesn't support any kind of caching. Hope it helps <?php class SoapAuthClient extends SoapClient { /** * Since the PHP SOAP package does not support basic authentication * this class downloads the WDSL file using the cURL package and * creates a local copy of the wdsl on your server. * Make sure you provide the following additional parameter in the * $options Array: * wdsl_local_copy => true */ private $cache_dir = '/home/xxxx/htdocs/cache/'; private $cache_url = 'http://www.xxxx.com/cache/'; function SoapAuthClient($wdsl, $options) { if (isset($options['wdsl_local_copy']) && $options['wdsl_local_copy'] == true && isset($options['login']) && isset($options['password'])) { $file = md5(uniqid()).'.xml'; if (($fp = fopen($this->cache_dir.$file, "w")) == false) { throw new Exception('Could not create local WDSL file ('.$this->cache_dir.$file.')'); } $ch = curl_init(); $credit = ($options['login'].':'.$options['password']); curl_setopt($ch, CURLOPT_URL, $wdsl); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $credit); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_FILE, $fp); if (($xml = curl_exec($ch)) === false) { //curl_close($ch); fclose($fp); unlink($this->cache_dir.$file); throw new Exception(curl_error($ch)); } curl_close($ch); fclose($fp); $wdsl = $this->cache_url.$file; } unset($options['wdsl_local_copy']); unset($options['wdsl_force_local_copy']); echo $wdsl; parent::__construct($wdsl, $options); unlink($this->cache_dir.$file); } } ?> ---- Server IP: 194.153.94.10 Probable Submitter: 85.4.218.207 ---- Manual Page -- http://www.php.net/manual/en/soapclient.soapclient.php Edit -- https://master.php.net/note/edit/101503 Del: integrated -- https://master.php.net/note/delete/101503/integrated Del: useless -- https://master.php.net/note/delete/101503/useless Del: bad code -- https://master.php.net/note/delete/101503/bad+code Del: spam -- https://master.php.net/note/delete/101503/spam Del: non-english -- https://master.php.net/note/delete/101503/non-english Del: in docs -- https://master.php.net/note/delete/101503/in+docs Del: other reasons-- https://master.php.net/note/delete/101503 Reject -- https://master.php.net/note/reject/101503 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175096) next »