Php 如何通过curl传递包含特殊字符的数据 我无法通过curl发布包含特殊字符的数据,有解决方案吗?
第一个代码是我的curl函数,第二个代码是我需要传递的数据Php 如何通过curl传递包含特殊字符的数据 我无法通过curl发布包含特殊字符的数据,有解决方案吗?,php,curl,Php,Curl,第一个代码是我的curl函数,第二个代码是我需要传递的数据 $communication_data_string = 'token='.json_encode(array( "activityTypeId"=>12, "activityId"=>5, "userID"=> 10, "partyID"=>20, "message_area_name"=>("this is my test data with special ch
$communication_data_string = 'token='.json_encode(array(
"activityTypeId"=>12,
"activityId"=>5,
"userID"=> 10,
"partyID"=>20,
"message_area_name"=>("this is my test data with special cheractors&&!@##$%$%%*)++")
)
);
echo(datPostingCURL($url, $communication_data_string));
?>
如果messageData包含特殊字符,则似乎不返回任何内容。请检查以下代码。我在本地系统中进行了测试。在我的www控制器中,我创建了一个名为“test”的文件夹来保存代码。然后我在那个“测试”文件夹中创建了两个文件。一个用于发送请求的文件和一个用于处理请求的文件 1.curl.php
2.curl_post.php
注意:当使用特殊字符时,您应该对该字符串进行编码。我试图用htmlspecialchars()
转换它。但它不起作用。所以我在这里使用了base64
编码方法 试试看
或
使用实体代码如何
@ = %40
& = %26
换线
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
到
由于您没有使用任何特定的post变量,因此将按照以下方式接收它
$data = urldecode(file_get_contents('php://input'));
你能给出$data_字符串吗?{“message_area_name”:“hai..这是我的测试数据。!@#$%$%*)+“}你应该编码特殊字符$details=json_decode($details)$message\u area\u name=$details->message\u area\u name;当我获取上面的消息\u area\u name时,它不会返回任何内容,因为数据中有特殊字符
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($data_string));
$data = urldecode(file_get_contents('php://input'));