CURLOPT POSTFIELDS没有将数据附加到HTTP请求

时间:2012-05-14 01:15:07

标签: php curl http-request

我一直试图通过HTTP请求发送一些东西,使用CURLOPT POSTFIELDS并且数据似乎没有传输。我错过了什么吗?

        function sendTestCase($caseArgs){
        try{
            $ch = curl_init();
            $sendData = http_build_query($caseArgs);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $sendData);
            curl_setopt($ch, CURLOPT_URL, 'http://localhost:8888/testrail/index.php?/miniapi/add_case/');  
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_POST, 1);

            curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));

            curl_exec($ch);
        }
        catch (HttpException $ex){
            echo $ex."<-Exception";
 }

 curl_close($ch);
    }

1 个答案:

答案 0 :(得分:1)

POSTFIELDS完全能够接受数组,curl会为你做网址建设。就像现在一样,你传入一个字符串来卷曲(恰好包含你的表单值),但不传入一个字段名,所以curl发出一个简单的字符串。试试这个:

 curl_setopt($ch, CURLOPT_POSTFIELDS, $caseArgs);