I\'m loving the Guzzle framework that I just discovered. I\'m using it to aggregate data across multiple API\'s using different response structures. It\'s worked find with JSON
Guzzle HTTP can be used for SOAP requests & works like a charm:
Below is the way I have implemented.
Create variables:
public function __construct(Request $request) {
$this->request = $request;
$this->openSoapEnvelope = '';
$this->soapHeader = '
<-- any header data goes here-->
';
$this->closeSoapEnvelope = ' ';
}
Create a function to form a soap request.
public function generateSoapRequest($soapBody){
return $this->openSoapEnvelope . $this->soapHeader . $soapBody . $this->closeSoapEnvelope;
}
Define a body & call generateSoapRequest method. e.g:
$soapBody = '
';
$xmlRequest = $this->generateSoapRequest($soapBody);
$client = new Client();
$options = [
'body' => $xmlRequest,
'headers' => [
"Content-Type" => "text/xml",
"accept" => "*/*",
"accept-encoding" => "gzip, deflate"
]
];
$res = $client->request(
'POST',
'http://your-soap-endpoint-url',
$options
);
print_r($res->getBody());