【发布时间】:2013-12-20 01:23:02
【问题描述】:
我这里发生了一些非常奇怪的事情。我正在使用 CodeIgniter 构建一个 API,该 API 使用通过 CURL 发布到它的数据。
一个 WordPress 网站正在向 CodeIgniter API 发布信息,并且一切正常,除了密码输入字段发布包含 @ 的字符串。
我直接将其归结为 XSS 保护,但已禁用。我没有收到 CURL 错误,并且 CodeIgniter 方法没有接收到数据(但是当没有 @ 时)。
我已经尝试了所有方法,谷歌搜索无济于事,尝试使用 htmlentities(),没有任何运气。
我已经尝试在数据传递给 CURL 之前打印 $_POST['fieldname'] 并将字符串打印回来(即使包含'@'),并且在 codeIgniter 端进行调试,我已经尝试获取返回发送数据的方法,除非发送的数据包含@。最后,尝试使用我的 REST 客户端测试 codeIgniter API,并且在使用 @ 发送字符串时奇怪地工作正常,所以我猜 CURL 命令有问题?
提前致谢。 斯特
-- 编辑:代码--
/* WORDPRESS SITE */
// ....
// When $_POST['pass'] doesn't contain '@' it passes data fine,
// print $_POST['pass'] works too even with an '@'...
// ...also tried htmlentities($_POST['pass']) with no luck
$data_to_post = array('pass' => $_POST['pass'], 'user' => $_POST['user']);
$result = do_api_call('return_posted_values', $data_to_post);
// ....
function do_api_call($method, $request = array()) {
$ch = curl_init(API_URL.$method);
// Add the api key to the request
$request['api_key'] = API_KEY;
foreach ($request as $key => $value) {
// Serialize any arrays
if (is_array($value)) $request[$key] = serialize($value);
}
// Set the curl
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
//print $result;
$result = json_decode($result);
return $result;
}
/* CODEIGNITER SIDE */
/* THIS METHOD IS IN API CLASS */
public function return_posted_values() {
// Return the posted data as string works fine when the data has no @
$return $this->input->post('user').' - '.$this->input->post('pass');
$this->response($return);
}
【问题讨论】:
-
贴出你的代码,没有看到它,我们无法告诉你你做错了什么或没有做什么......
标签: php api codeigniter post curl