通过curl php发送url编码数据时出错

时间:2014-05-07 10:20:13

标签: php post curl

这是我的CURL帖子的PHP代码:

$post = array("field1"=>"data1%%Fval","field2"=>"data2%%12 Add");

$fields = "";

$i = 0;
foreach ($post as $key => $value) {
$fields .= ($i > 0) ? "&" . "$key=" . urlencode($value) : "$key=" .    urlencode($value);
$i++;
};

set_time_limit(60);
$output = array();
$curlSession = curl_init();
curl_setopt ($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt ($curlSession, CURLOPT_POST, 1);
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $fields);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlSession, CURLOPT_TIMEOUT,30);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 0);

$rawresponse = curl_exec($curlSession);

当我使用上面的代码通过php CURL发布url编码数据时,我没有在服务器端获得URL编码数据,我在那里收到数据作为帖子。

似乎我的代码有任何在发送数据之前自动执行URL解码的问题。

任何人都可以告诉我这个问题的解决方案吗?

0 个答案:

没有答案