Forum Moderators: coopster

Message Too Old, No Replies

problems with Curl and XML post to suppplier

         

neonpie

2:08 pm on May 3, 2007 (gmt 0)

10+ Year Member



I have been having problems with an xml post to a suppliers website. i was getting a returned "Document Error", but after reading this post [webmasterworld.com...]

i have now got past one problem and i am now faced with another after adapting the code posted in the above link.

This time my error is "Wrong Number of Lines, or Line missingLINE ERROR".

I have contacted the supplier and they said the xml I sent to them in an email was correct, but as they dont know php they couldnt help me with why I was getting this problem.

here is the full code i am using:

$request = '<?xml version="1.0" standalone="yes"?>
<order>
<header>
<securitycode>testcode</securitycode>
<orderref>TEST IGNORE</orderref>
<orderdatetime>'.date("m/d/Y H:i:s").'</orderdatetime>
<daterequired>'.date("m/d/Y").'</daterequired>
<deliveryaddress>
<deliverycontact>MR Smith</deliverycontact>
<deliveryname>Smith Shops</deliveryname>
<addressline1>addressline1</addressline1>
<addressline2>addressline2</addressline2>
<addressline3>addressline3</addressline3>
<addressline4>addressline4</addressline4>
<postcode>AA1 1AA</postcode>
</deliveryaddress>
</header>
<line>
<lineno>1</lineno>
<tlcpartno>PF7SS320</tlcpartno>
<quantity>10</quantity>
</line>
</order>';

// Create Headers
$header[] = "Host: www.supplierswebsite.com";
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($request) . "\r\n";
$header[] = $request;

// Send using CURL
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://www.supplierswebsite.com/getxml.asp?action=ORDER&account=testing"); // URL to post
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); // headers from above
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$result);

$result = curl_exec( $ch ); // runs the post
curl_close($ch);

echo $result; // echo reply response

as mentioned above, the $result returns - "Wrong Number of Lines, or Line missingLINE ERROR"

any ideas where i am going wrong?

thanks in advance

phparion

8:17 am on May 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



where this $result is coming from?

curl_setopt($ch, CURLOPT_POSTFIELDS,$result);

i think this should be

curl_setopt($ch, CURLOPT_POSTFIELDS,$request);

neonpie

12:42 pm on May 4, 2007 (gmt 0)

10+ Year Member



thanks phparion.
well spotted on the $result, yes i should have been $request. however that was not my problem.
curl_setopt($ch, CURLOPT_POSTFIELDS,$request);

i have since been on the phone again to the tech guy and after a while we figured out it was one of the names was different to what he had sent me and what he had set up on there server.

overall though it was good as we came across some problems with some of the status messages that was being returned.

Thanks