使用curl发布参数是错误的,而使用php Yii的CURL是可以的

时间:2017-04-05 11:29:50

标签: curl

下面的代码是php使用YII框架发布参数。

    public static $_host = 'http://example.com';
    private static $_id = 123;
    private static $_key = '432543253';
    public $_client;
    public $params;

    function __construct() {
        $this->initizlize();
    }

    public function initizlize() {
        $this->_client = new RESTClient();
        $config = array(
            'server' => self::$_host
        );
        $this->params = array(
            'id' => self::$_id,
            'key' => self::$_key
        );
        $this->_client->initialize($config);
    }
    
    public function geList($date = null) {
        $uri = 'file/list';
        $date = $date ? $date : Date('Y-m-d');
        $this->params['date'] = $date;
        $result = $this->_client->post($uri, $this->params);
        return $this->parseResult($result);
    }

然后我尝试使用curl命令来做同样的事情。

curl -i -H 'content-type:application/json' -d  '{"date":"2017-04-05","key":"432543253","id":123}' "http://example.com"
但结果是这样的 { “RETCODE”:1, “retmsg”:{ “300”:[ “ID”, “键”]} “错误代码”:102}

我不熟悉php,我的curl命令出了什么问题?

1 个答案:

答案 0 :(得分:0)

我已使用

解决了这个问题



curl -i -H 'charset=UTF-8' -F  'date=2017-04-05' -F 'key=432543253' -F 'id=123' -X POST  "http://example.com"