[英]Can't post @ to API via curl PHP
我在這里發生一些非常奇怪的事情。 我正在使用CodeIgniter構建API,該API使用通過CURL發布到它的數據。
WordPress網站正在將信息發布到CodeIgniter API,並且除了密碼輸入字段發布包含@的字符串之外,其他所有功能都正常運行。
我立即將其歸結為XSS保護,但這已被禁用。 我沒有CURL錯誤,並且CodeIgniter方法未接收到數據(但是沒有@時)。
我已經嘗試了一切,用谷歌搜索都無濟於事,嘗試使用htmlentities(),沒有任何運氣。
我試過在數據傳遞到CURL之前打印$ _POST ['fieldname']並打印回字符串(即使包含'@'時也是如此),並在codeIgniter端進行調試,我嘗試了一種方法來返回發送的數據,除非發送的數據包含@。 最后,嘗試使用我的REST客戶端測試codeIgniter API,當使用@發送字符串時,這種方法工作正常,因此我猜CURL命令有問題嗎?
提前致謝。 Ste
-編輯:代碼-
/* 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);
}
將@替換為密碼中的%40。 或在密碼上使用urlencode()函數來轉義這些字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.