+ being converted to space when sending POST data with CURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exxx
Forum Newbie
Posts: 4
Joined: Mon Oct 10, 2005 3:44 pm

+ being converted to space when sending POST data with CURL

Post by exxx »

Code: Select all

<?php
$URL="secure.comodo.net/products/!DecodeCSR";
$ch = curl_init();    
curl_setopt($ch, CURLOPT_URL,"http://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
header('Content-type: text/plain;');
curl_setopt($ch, CURLOPT_POSTFIELDS, "csr=".$_POST['csr']."&showcsr=Y");
$response = nl2br(curl_exec ($ch));    
curl_close ($ch);
?>
http://s93549175.onlinehome.us/comodo/decode_csr.php

showcsr=Y shows the CSR input again....and it always converts +s into spaces...

this is a problem because CSRs have +s in them...and when they are converted into spaces the CSR cannot be decoded.

here is a sample CSR that SHOULD be validated (but is not due to the +s being changed to spaces)
-----BEGIN CERTIFICATE REQUEST-----
MIIBzTCCATYCAQAwgYwxCzAJBgNVBAYTAmdiMQ8wDQYDVQQIEwZMb25kb24xDzAN
BgNVBAcTBkxvbmRvbjEZMBcGA1UEChMQU3BhY2VTdXJmZXIgTHRkLjEZMBcGA1UE
AxMQd3d3LnNwYWNlcmVnLmNvbTElMCMGCSqGSIb3DQEJARYWd2VibWFzdGVyQHNw
YWNlcmVnLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAywfuXnd348ot
iAcZ4RHFc509ImCTagKaNkiQ4xyijbPYP7H0UQ5iXqvojSIcbUOVhExqwqyqjCPm
7ZpON3IXktIcKAwPFvoqKkHuqTa8KMnZTSY8P7QILYHFd2Sd1l1arCrWv8HWb+qM
RHVTlviBaLAHQxnz28qKkYN09K0fw5cCAwEAAaAAMA0GCSqGSIb3DQEBBAUAA4GB
AFMgp2KkHQXMC1JbZf3AkIz7mrl4X21cRusTfd8ec3RuMZexGy76jMGFyPWVM69R
Fvpfiic8h28HrHube7pEPFpdUSj2cR4OZCAg5uqzN/ESwc4CtLzej7pWoDPpc/kv
hiJ/eGOxINKd39kCuzIS6zrvb2ihJth7jcmokezmrwjQ
-----END CERTIFICATE REQUEST-----
Does anyone know why this is happening? I suspect it may have something to do with the content-type...but it's hard to say.

Thanks in advance for any help, it is greatly appreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

rawurlencode() the data.
exxx
Forum Newbie
Posts: 4
Joined: Mon Oct 10, 2005 3:44 pm

Post by exxx »

Great, thanks a lot, works now :)
Post Reply