cURL with SOAP headers.

Hi, I am sending xml using cURL and today I ran into SOAP requirement for the first time. rather then implement something like nuSOAP and save myself some time. Is there any way to add the SOAP Elements using cURL.  Below is the soap header requirements i need to include somehwo and below that is a snippet of my code. . without the xml, the xml is stored as $xml_request.
// REQUIREMENTS I NEED TO INCLUDE

POST /dfswebsrvc/dfswebsrvc.asmx HTTP/1.1
Host: usportal.duplium.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://duplium.com/dfswebsrvc/InsertOrder"

<?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>
    <InsertOrder xmlns="http://duplium.com/dfswebsrvc/">
      <ticket>string</ticket>
      <programID>string</programID>
      <orderInfo>string</orderInfo>
    </InsertOrder>
  </soap:Body>
</soap:Envelope>


// MY CODE THUS FAR - i send the request then store the response to a tmp directory

          /* Use CURL to execute XML POST and write output to the temp file */
          $ch = curl_init (GATEWAY_URL);
          curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt ($ch, CURLOPT_POST, 1);
          curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml_request);
          curl_setopt ($ch, CURLOPT_FILE, $fh);
          curl_exec($ch);
          curl_close($ch);

          /* Read data from file into a string buffer */
          rewind ($fh);
          while (!feof($fh)) {
              $xml_response .= fgets($fh, 1024);
          }

          $this->parser = xml_parser_create();

          /* Disable XML tag capitalisation (Case Folding) */
          xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, FALSE);

          /* Define Callback functions for XML Parsing */
          xml_set_object($this->parser, &$this);
          xml_set_element_handler ($this->parser, "ep_xml_element_start", "ep_xml_element_end");
          xml_set_character_data_handler ($this->parser, "ep_xml_data");

          /* Parse the XML response */
          xml_parse($this->parser, $xml_response, TRUE);
                                                      //      exit();
          /* Clean up after ourselves */
          xml_parser_free ($this->parser);
          fclose ($fh);

redcableAsked:
Who is Participating?
 
jkmyoungCommented:
Before you execute this line:
curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml_request);

 change the $xml_request to have the soap layer. Why not just prepend and append the wrapper onto it? Eg something like:

$xml_request = "<?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>" +
      $xml_request +
    " </soap:Body>" +
  "</soap:Envelope>";
0
 
redcableAuthor Commented:
when i try that i get this

Unable to handle request without a valid action parameter. Please supply a valid soap action.
0
 
virmaiorCommented:
redcable,
  did you ever figure out the answer to this?  I am experiencing an identical outcome for sending a SOAP request via cURL.
0
 
jkmyoungCommented:
My guess is the <soap:Header> was missing.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.