Forum Moderators: open

Message Too Old, No Replies

posting xml with curl and php

problems posting xml with curl and php

         

michaelh613

3:52 pm on Mar 18, 2008 (gmt 0)

10+ Year Member



I have created an xml form using dom


<?php
$dom = new DOMDocument('1.0');
//create root element <Request_group> and append it to the document
$REQUEST_GROUP = $dom->appendChild($dom->createElement('REQUEST_GROUP'));
$REQUEST_GROUP->setAttribute('MISMOVersionID','2.1');

$REQUEST=$REQUEST_GROUP->appendChild($dom->createElement('REQUEST'));
$REQUEST->setAttribute('LoginAccountIdentifier','testuser');
$REQUEST->setAttribute('LoginAccountPassword','Password');

$KEY=$REQUEST->appendChild($dom->createElement('KEY'));
$KEY->setAttribute('_Name','MemberID');
$KEY->setAttribute('_Value','100');

$REQUEST_DATA=$REQUEST->appendChild($dom->createElement('REQUEST_DATA'));
$CREDIT_REQUEST=$REQUEST_DATA->appendChild($dom->createElement('CREDIT_REQUEST'));
$CREDIT_REQUEST->setAttribute('MISMOVersionID','2.1');

$CREDIT_REQUEST_DATA=$CREDIT_REQUEST->appendChild($dom->createElement('CREDIT_REQUEST_DATA'));
$CREDIT_REQUEST_DATA->setAttribute('CreditRequestID','CRReq0001');
$CREDIT_REQUEST_DATA->setAttribute('BorrowerID','BorRec0001');
$CREDIT_REQUEST_DATA->setAttribute('CreditReportRequestActionType','Submit');
$CREDIT_REQUEST_DATA->setAttribute('CreditReportType','Consumer');
$CREDIT_REQUEST_DATA->setAttribute('CreditRequestType','Individual');

$CREDIT_REPOSITORY_INCLUDED=$CREDIT_REQUEST_DATA->appendChild($dom->createElement('CREDIT_REPOSITORY_INCLUDED'));
$CREDIT_REPOSITORY_INCLUDED->setAttribute('_EquifaxIndicator','N');
$CREDIT_REPOSITORY_INCLUDED->setAttribute('_ExperianIndicator','Y');
$CREDIT_REPOSITORY_INCLUDED->setAttribute('_TransUnionIndicator','N');

$LOAN_APPLICATION=$CREDIT_REQUEST->appendChild($dom->createElement('LOAN_APPLICATION'));
$BORROWER=$LOAN_APPLICATION->appendChild($dom->createElement('BORROWER'));
$BORROWER->setAttribute('BorrowerID','BorRec0001');
$BORROWER->setAttribute('_FirstName','EVPAULA');
$BORROWER->setAttribute('_MiddleName','');
$BORROWER->setAttribute('_LastName','Consumer');
$BORROWER->setAttribute('_SSN','376988419');

$_RESIDENCE=$BORROWER->appendChild($dom->createElement('_RESIDENCE'));
$_RESIDENCE->setAttribute('_StreetAddress','10655 Birch St');
$_RESIDENCE->setAttribute('_City','Burbank');
$_RESIDENCE->setAttribute('_State','Ca');
$_RESIDENCE->setAttribute('_PostalCode','20906');

$dom -> formatOutput = true;
$result= $dom->saveXML();
?>

Now I need to post it to an external URL using CURL and it fails


<?php
Require 'createquidataxml.php';
$Result = simplexml_load_string($result);
$xmlResult= $Result->asXML();
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, "http://www.example.net/test_data.php");

curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlResult);
curl_setopt($ch, CURLOPT_POST,1);

curl_exec($ch);

It seems the issue is the xml file comes over as an array and they are expecting a DOM objct. As you can see I am using PHP in Curl.

Any throubleshooting suggstions welcom

[edited by: encyclo at 10:57 pm (utc) on Mar. 21, 2008]
[edit reason] switched to example.net [/edit]

httpwebwitch

5:21 pm on Mar 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



everything here looks correct, but ... code often looks correct until you execute it.
Are you getting a PHP error? If so, what does it say?
It may help to bounce this one over to the PHP forum

michaelh613

6:12 pm on Mar 19, 2008 (gmt 0)

10+ Year Member



Strange thing is this worked

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //Don't verify ssl certificate
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost);

$reply = curl_exec($ch);

Didn't have to set any headers and took out

curl_setopt($ch, CURLOPT_POST,1);

Which I thought was needd to tell curl to use a POST and not a get.

I do not understand why this worked but I am not complaining.

Thanks fo rthe help