base64 through cURL - where did my + go?
Posted: Thu Oct 21, 2010 8:52 am
I am trying to post a base64 encoded XML string through cURL but am running into a very odd problem. When the string reaches the server I am posting to, all of the + signs have been converted to a space! This obviously breaks the world, causes planes to fall from the sky, and makes horses start eating each other. No good.
Here is what I have done. This is on server 1:
Then on server 2 (the valid-url.com server):
Then I compare the results and, very oddly, on server 2 the output has spaces in it, spaces where a + should be.
One fix would be simply to do this on server 2:
which would work but just feels soooo dirty, dirtier than _______!
So, I come to the masses to ask my humble question, wtf is going on here? Anyone ever see something like this before?
Edit: I took the correct base64 encoded string and posted it via a HTML form and it worked, so the problem has to be in cURL.
Here is what I have done. This is on server 1:
Code: Select all
$url = 'https://valid-url.com/xml.php';
echo base64_encode($requestXML);//I echo out my end first, to make sure I am not going nuts
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.base64_encode($requestXML));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL
$contents = curl_exec($ch);Code: Select all
<?php
echo $_POST['xml'];die();One fix would be simply to do this on server 2:
Code: Select all
<?php
echo str_replace(' ', '+', $_POST['xml']);die();So, I come to the masses to ask my humble question, wtf is going on here? Anyone ever see something like this before?
Edit: I took the correct base64 encoded string and posted it via a HTML form and it worked, so the problem has to be in cURL.