How to call soap API in PHP and Postman soap
TechTechInfo.com » How to call soap API in PHP and Postman soap

How to call soap API in PHP and Postman soap

soap api in postman
soap api in postman
This entry is part 2 of 7 in the series PHP Advance Tutorial

SOAP – Simple Object Access Protocol.it uses the only XML for exchanging information From the client-side to the server-side. we can use any of the languages to consume this api.there is no language dependency. you can use any internet protocol like TCP, UDP. also soap API use user-defined Https codes. these APIs are more secure than other APIs. so that mostly used by the banking industry.

In this, We will use soap API with

SOAP API with the Postman

Step 1. Download and install the postman 

Step 2. We will use this http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL

soap API for testing

Step 3. Request data for this API 

<pre>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
		<ListOfContinentsByName xmlns="http://www.oorsprong.org/websamples.countryinfo"/>
	</Body>
</Envelope>
</pre>

If you unable to produce the request data add  this  chrome extension wizdler

wizdler soap api extension
wizdler soap api extension

Click on ListOfCountryByName. you will redirect on the new tab then copy the request data.

Step 4. Then a select  method to Post 

postman api call method
postman api call method

Step 5. Add content type in the header to text/XML

set header in postman
set header in postman

Step 6. Welldone All set now press the send button and we will the response in XML formate from your soap API.

soap api call in postman

Calling soap api using the PHP

For consuming the soap API in PHP we will use the predefined curl method 

To call this API in PHP by curl method you have to set these parameters

CURLOPT_URL=>” ”
CURLOPT_POSTFIELDS =>” ”
CURLOPT_HTTPHEADER =>” ”

This is the demo code for reference. past this code into your project  and remember pls change the  CURLOPT_URL and CURLOPT_POSTFIELDS

<pre>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => 
  "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">
  <Body>
      <ListOfContinentsByCode xmlns=\"http://www.oorsprong.org/websamples.countryinfo\"/>
  </Body>
</Envelope>",
  CURLOPT_HTTPHEADER => array("content-type: text/xml"),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>
</pre>
//call soap API in php
call soap api by php
call soap api by php

Make index.php into your project and try to access this file in the browser. Make sure you have made this project into the localhost root directory.

soap api call on localhost using chrome

Series Navigation<< How to Install and Use Composer or PHP Dependency ManagerHow to optimize the php two-dimensional search  >>
soap api in postman
Join the discussion

1 comment
Translate »
Share via
Copy link
%d bloggers like this: