Skip to content

Instantly share code, notes, and snippets.

@imzhi
Created July 31, 2015 03:48
Show Gist options
  • Save imzhi/ad676c0b62491d0edfab to your computer and use it in GitHub Desktop.
Save imzhi/ad676c0b62491d0edfab to your computer and use it in GitHub Desktop.
PHP Soap
<?php
$c = new SoapClient(null, array('uri' => 'http://localhost/tests/php_practice', 'location' => 'http://localhost/tests/php_practice/server.php', 'trace' => true));
$h = new SoapHeader('http://localhost/tests/php_practice', 'auth', '123456', false, SOAP_ACTOR_NEXT);
$c->__setSoapHeaders($h);
try {
echo $c->say();
} catch (Exception $e) {
echo $e->getMessage();
}
<?php
class Server
{
public function auth($a)
{
if ($a != '123456') {
throw new SoapFault('Server', '禁止访问');
}
}
public function say() {
return 'hi';
}
}
$s = new SoapServer(null, array('uri' => 'http://localhost/tests/php_practice/server.php'));
$s->setClass('Server');
$s->handle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment