Sending a header using the PHP SOAP client

September 30th, 2012 by laeeq | No comments

You can create your own SOAP Client to send a header in a minute using PHP. PHP provides SOAP API which has numerous functions to create SOAP Client, initialize SOAP Header and also setting SOAP Header.

Actually when interacting with SOAP Server, the server requires a header to be sent which have API key. The header name will be APIKEY and the value will be the key itself. In example below the namespace is used for the API call is “MyNamespace”.

For initialization of SOAP client and set the header using PHP, you can do like below, where $wsdl_url is the URL of the WSDL file for the SOAP request:

  1. $wsdl_url=“http://localhost/code/soap.wsdl”;
  2. $soap_client = new SoapClient($wsdl_url);
  3. $soap_header = new SoapHeader(‘ExampleNamespace’, ‘APIKey’, $apiKey);
  4. $soap_client->__setSoapHeaders($soap_header);

Now you are ready to make requests to the SOAP server and the header will be sent with each time.

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Wrapping Text using PHP
  • PHP 5.5 beta 4 is now available
  • Swapping Array Keys and Values
  • PHP Security
  • Working with Image Metadata in PHP
  • Converting Between Relative and Absolute File Path
  • Parsing File Paths with PHP
  • How to remove HTML Comments with PHP?
  • How to access .htaccess values?
  • Dealing With Common PHP Errors
  • Interview Questions and Answers for Freshers
  • Display numbers with ordinal suffix using PHP
  • Function to set COLLATION on database fields of Mysql
  • Read and write to remote files using PHP
  • Sharing PHP SESSION Variables between Multiple Subdomains
  • PHP 5.5.0 Alpha4 Development Preview Released
  • Check a string starts with http using PHP
  • Cross-Site Scripting Attacks (XSS)
  • PHP 5.4.11 and PHP 5.3.21 released!
  • PHP Memory Leak Issue
  •  

     

    1. No comments yet.
    1. No trackbacks yet.