【发布时间】:2012-05-02 01:39:11
【问题描述】:
我有下一个代码:
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.mydomain.com/test.php');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS,"First Name=Jhon&Last Name=bt");
curl_exec ($c);
curl_close ($c);
我的问题是这段代码中的空格:
"First Name=Jhon&Last Name=bt"
我尝试了下一个代码:
$test=rawurlencode("First Name=Jhon&Last Name=bt");
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.mydomain.com/test.php');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS,$test);
curl_exec ($c);
curl_close ($c);
我也试过了
$first_name=rawurlencode("名字");
$last_name=rawurlencode("姓氏");
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.mydomain.com/test.php');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS,"$first_name=Jhon&$last_name=bt");
curl_exec ($c);
curl_close ($c);
我的错误是什么?不管用。我需要使用变量“名字”和“姓氏”的名称发送。感谢您的帮助。
【问题讨论】:
-
在下面查看我的更新答案。如果您从变量名中删除引号并正确连接,您的解决方案可能会起作用。