Page 1 of 1

Posting xml using curl

Posted: Tue Mar 18, 2008 9:50 am
by michaelh613
Everah | Please use bbCode tags when posting code in the forums.

I am posting xml using curl and it isn't being read by the receiving server correctly.

The server is receiving the post as a array it sees

Code: Select all

array(1) {
  ["<?xml_version"]=>
  string(972) "\"1.0\"?>
<REQUEST_GROUP MISMOVersionID=\"2.1\">
  <REQUEST LoginAccountIdentifier=\"testuser\" LoginAccountPassword=\"Password\">
    <KEY _NAME=\"MemberID\" _Value=\"100\"/>
    <REQUEST_DATA>
      <CREDIT_REQUEST MISMOVersionID=\"2.1\">
        <CREDIT_REQUEST_DATA CreditRequestID=\"CRReq0001\" BorrowerID=\"BorRec0001\" CreditReportRequestActionType=\"Submit\" CreditReportType=\"Consumer\" CreditRequestType=\"Individual\">
          <CREDIT_REPOSITORY_INCLUDED _EquifaxIndicator=\"N\" _ExperianIndicator=\"Y\" _TransUnionIndicator=\"N\"/>
        </CREDIT_REQUEST_DATA>
        <LOAN_APPLICATION>
          <BORROWER BorrowerID=\"BorRec0001\" _FirstName=\"EVPAULA\" _MiddleName=\"\" _LastName=\"Consumer\" _SSN=\"376988419\">
            <_RESIDENCE _StreetAddress=\"10655 Birch St\" _City=\"Burbank\" _State=\"Ca\" _PostalCode=\"20906\"/>
          </BORROWER>
        </LOAN_APPLICATION>
      </CREDIT_REQUEST>
    </REQUEST_DATA>
  </REQUEST>
</REQUEST_GROUP>
"
}
My curl is

Code: Select all

 
$ch= curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Accept: text/xml"));
curl_setopt($ch, CURLOPT_URL, "http://www.horowitzfamily.net/test_data.php");      
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlResult);
curl_setopt($ch, CURLOPT_POST,1);
curl_exec($ch)
 
the / before " are being added by the post as escape characters.

My first question is should the xml be posted as an array. I know a normal post is. I'm not sure if my issue is my post or on the receiving server. What their tech support is telling me is they are looking for the xml to be posted as a dom object.

Thanks for any help.

Everah | Please use bbCode tags when posting code in the forums.

Re: Posting xml using curl

Posted: Tue Mar 18, 2008 11:30 am
by Zoxive
Is that dump in the beginning the value of $xmlResult?

If it is, as I stated in your previous post the data needs to have a name. When you post data in normal forums it is labeled with names. ex <input name="myname">

In all of my projects which used curl and xml, i had to name my xml as per the server requested.
In my case it was just xml=.

So to point it out more clearly, I had either

Code: Select all

$postData = array(
  'xml'  => $xmlData,
);
OR

Code: Select all

$postData = 'xml=' . $xmlData;

Code: Select all

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
Post Data can and normally has other params too.

Some services even require encoding, and hashing.

Re: Posting xml using curl

Posted: Tue Mar 18, 2008 12:27 pm
by michaelh613
Zoxive wrote:Is that dump in the beginning the value of $xmlResult?

If it is, as I stated in your previous post the data needs to have a name. When you post data in normal forums it is labeled with names. ex <input name="myname">

In all of my projects which used curl and xml, i had to name my xml as per the server requested.
In my case it was just xml=.

So to point it out more clearly, I had either

Code: Select all

$postData = array(
  'xml'  => $xmlData,
);
OR

Code: Select all

$postData = 'xml=' . $xmlData;

Code: Select all

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
Post Data can and normally has other params too.

Some services even require encoding, and hashing.

I've done what you said and didn't resolve the issue

Code: Select all

 
<?php
Require 'createquidataxml.php';
$Result = simplexml_load_string($result);
$xmlResult= $Result->asXML();
$postData = 'xml=' .$xmlResult;
 
 
//echo $xmlResult;
//die();
 
 
$ch= curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Accept: text/xml"));
curl_setopt($ch, CURLOPT_URL, "https://www.reportspace.net/partner/externalconsumerrequestV2.asp?subscriber=232cis&customer=AGILE");
curl_setopt($ch, CURLOPT_URL, "http://www.horowitzfamily.net/test_data.php");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_POST,1);
curl_exec($ch);
 
Have you ever heard of someone wanting a post of a DOM object. Thats what the tech guy on the other end said.
He wasn't sure what he really wanted and is confusing me.

Re: Posting xml using curl

Posted: Tue Mar 18, 2008 12:51 pm
by RobertGonzalez
Maybe he is talking about the PHP DOM Object?