Posting xml using curl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michaelh613
Forum Commoner
Posts: 38
Joined: Sun Mar 16, 2008 1:35 pm

Posting xml using curl

Post 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.
Last edited by RobertGonzalez on Tue Mar 18, 2008 12:49 pm, edited 1 time in total.
Reason: Tags note. Again.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Posting xml using curl

Post 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.
michaelh613
Forum Commoner
Posts: 38
Joined: Sun Mar 16, 2008 1:35 pm

Re: Posting xml using curl

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Posting xml using curl

Post by RobertGonzalez »

Maybe he is talking about the PHP DOM Object?
Post Reply