繁体   English   中英

无法通过curl PHP将@发布到API

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM