0

I've been trying to send something via HTTP request, using the CURLOPT POSTFIELDS and the data doesn't seem to transfer. Am I missing something?

        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);
    }
John Conde
  • 217,595
  • 99
  • 455
  • 496
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156

1 Answers1

1

POSTFIELDS is perfectly capable of accepting an array and curl will do the url-building for you. As it stands now, you're passing in a string to curl (which happens to contain your form values), but not passing in a field name, so curl is sending out a bare string. Try this instead:

 curl_setopt($ch, CURLOPT_POSTFIELDS, $caseArgs);
Marc B
  • 356,200
  • 43
  • 426
  • 500