We help IT Professionals succeed at work.

cURL with SOAP headers.

18,747 Views
Last Modified: 2013-11-18
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);

Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
when i try that i get this

Unable to handle request without a valid action parameter. Please supply a valid soap action.

Commented:
redcable,
  did you ever figure out the answer to this?  I am experiencing an identical outcome for sending a SOAP request via cURL.

Commented:
My guess is the <soap:Header> was missing.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.