curl-and-php
XML Body POST
Date: Wed, 01 Dec 2004 12:02:29 +0000
Hi
I need to send an XML message as a body (ie not as a standard name-value
form-encoded pair).
I have been using the following code to try and do this, but it does not
appear to send the XML.
I have tested the same target site using curl from the command line with
the -d flag and it behaves as expected.
As a work around, I am currently making a shell_exec call to the command
line curl, but I would prefer to bring this back inside the main php
script, so any help would be much appreciated!
Setup is...
curl 7.12.0
apache 2.0.49
php 5.0.2
The code....
<?php
$ch =
curl_init("http://localhost/tpmtest/nonauth/UserInput/TSX_IN_CREDITACCOUNT.xml");
//(sorry, not visible to the outside world)
$postData = "<?xml version='1.0' encoding='UTF-8'?><ROWSET><ROW
num='1'><B01>30149</B01><B02>biggles</B02><D01>1461</D01><G01>100</G01><G02>GBP</G02><Y02>6/6/1666
6:6:6</Y02></ROW></ROWSET>";
$httpHeaders = array("Content-Type" => "text/xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postData");
//curl_setopt($ch, CURLOPT_POSTFIELDS, "blah=$postData");
curl_exec($ch);
//output the last curl error, even if there wasn't one!
$lastError = curl_error($ch);
echo "<br><br>Last error was:- $lastError";
$lastReq = curl_getinfo($ch);
echo "<br><br>Last request was <br>";
print_r($lastReq);
curl_close($ch);
?>
You will probably notice from this that I have tried setting custom
header and this made no difference, and also that I have tried the
name-value pair for POST data, and that this did work (except that the
target page won't handle this!)
Thanks for any help
Tom
Received on 2004-12-01