Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: problem passing xml through curl
01-24-2013, 09:29 PM #1
- Join Date
- May 2008
- Thanked 5 Times in 5 Posts
problem passing xml through curl
So I am trying to pass an xml string through curl onto a server. Currently what I am getting back is:
XML Parsing Error: not well-formed
if I turn off header type setting it to 'Content-type: text/xml' so now its just text/plain, i get:
415 Unsupported Media Type
I have gone through my xml string and tested seperatly to make sure the string I passing is good. It is, assigning the string as text/xml will produce a valid xml page without any errors. so it seems that my curl setup is to blame for this.
here is my code:
$xmlToSend = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<user-agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.3; .NET CLR 2.0.50727)</user-agent>
$ch = curl_init();
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_URL, 'https://domain.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlToSend);
$result = curl_exec($ch);
Any ideas on what I am missing would be greatly appreciated
01-24-2013, 11:46 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
Guess it depends on precisely what is in those variables. If there's anything that disrupts the structure, that would blow it out of the water. Wrap them in cdata blocks to be sure.
The XML itself appears as well formed. Haven't a clue if its correct though.
If its fine for you, and its fine for me, than I'd suggest its where you're sending it that is tossing that error.
Curl wise, I guess that depends on what the server is doing. Its fine so long as they are pulling from the HTTP_RAW_POST_DATA. If they are not, than you will need to drop the content type as well as provide the input a fieldname in the post.
header('HTTP/1.1 420 Enhance Your Calm');