Jump to content

SOAP request in PHP with CURL


jaybo

Recommended Posts

I am sending a SOAP request and the response is 200 ok but I am struggling to output the $response.

This is the website for the request Calculator Web Service and also the xml file document tree http://dneonline.com/calculator.asmx?wsdl

Here is my php code;

 

<?php
$xml = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Add xmlns="http://tempuri.org/">
      <intA>1</intA>
      <intB>2</intB>
    </Add>
  </soap:Body>
</soap:Envelope>';

$url = "http://dneonline.com/calculator.asmx?wsdl";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$headers = array();
array_push($headers, "Content-Type: text/xml; charset=utf-8");
array_push($headers, "Accept: text/xml");
array_push($headers, "Cache-Control: no-cache");
array_push($headers, "Pragma: no-cache");
array_push($headers, "SOAPAction: http://tempuri.org/Add");

if($xml != null) {
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
    array_push($headers, "Content-Length: " . strlen($xml));
}

// curl_setopt($ch, CURLOPT_USERPWD, "user_name:password"); /* If required */
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "<pre>";
print_r($response->AddResponse);
echo "</pre>";
?>

 

Link to comment
Share on other sites

Three problems.

First is finding out exactly what $response contains. Try to print_r or var_dump it directly without any ->AddResponse or other changes. You'll discover that the response isn't what you think it is.
Second is that $response is a string, not an object.

Third, and arguably most important, is that you're implementing SOAP on your own instead of using PHP's existing SOAP functionality.

Link to comment
Share on other sites

I am seeing that $response returns bool(false).

 

I have been trying to use SoapClient but continuously get the error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https...'

I have looked in the php.ini file to address any exceptions and don't appear to get any success if I make adjustments there. This is the first time I have used SOAP and while it appears straight forward to me, I have some stumbling blocks to try to work though. As I have some experience of using cURL I have taken this route due to the resistance I am experiencing with SoapClient.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.