Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeRDark
languagephp
titleHTTP authentication with Fetch
linenumberstrue
collapsetrue
$usr = 'username';$pwd = 'password';
 
// method 1 - login details in URL
$url = "https://$user:$pwd@webservice.dmz.google.com";
$t->fetch($url);
 
// method 2 - login details in HTTP Header
$url = "https://webservice.dmz.google.com";
$headers = array('CURLOPT_USERPWD' => "$usr:$pwd");
$t->fetch($url, $post = '', $headers);
 
// return
echo $t->result;

Connecting to SOAP web services

Code Block
themeRDark
languagephp
titlePHP SOAP example
linenumberstrue
collapsetrue
$debug = 0;$usr = 'username';
$pwd = 'password';
 
$WSDL_URL = 'https://webservice2.dmz.mycompany.com';
 
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 0); 
 
$so_init = array(
    'login'         => $usr,
    'password'      => $pwd,
    'trace'         => $debug,
    'exceptions'    => $debug,
    'features'      => SOAP_SINGLE_ELEMENT_ARRAYS, // enable for easier responses in PHP
);
 
$so_client = new SoapClient($WSDL_URL, $so_init);
 
// you may need this line if your WSDL has incorrect hostnames
// $WSDL_Action = 'https://webservice2.dmz.mycompany.com';
// $so_client->__setLocation($WSDL_Action);
 
// view methods
// print_r($so_client->__getFunctions(), 1);
 
// invoke a method
$params = array('Username' => 'Bob');
$so = $so_client->MyMethod($params);
 
// view result
print_r($so, 1);