【发布时间】:2013-12-30 02:21:12
【问题描述】:
我一直在使用 PHP 和 curl 将敏感数据发布到我的后端服务器。但是,在第 2 次或第 3 次 post 请求之后,post 数据似乎并没有被清除,而是似乎将旧的 post 数据连接到正在发送的新数据。
这是我如何创建请求的示例:
function Communicate($req, $postdata)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, sprintf('%s%s', $this->server_uri, $req));
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, substr_count($postdata, '='));
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$res = curl_exec($curl);
curl_close($curl);
unset($postdata);
$sfr = json_decode($res);
}
如您所见,它相当简单。
但是,我正在后端服务器上跟踪发布请求,这是我得到的:
第一个请求
Restful 函数:ValidateUserByEmail 参数:email=sam.bengtson@gmail.com&pass=foo
第二次请求
Restful 函数:GetRegionByUserId 参数:userid=11.bengtson@gmail.com&pass=foo
第二个请求的用户 ID 参数应该只有 1。我可以看到在 curl_exec 函数执行之前已正确设置。
【问题讨论】: