有人告诉我,通过将数组传递给 CURLOPT_POSTFIELDS 会自动为您执行 URL 编码,但由于某种原因,它并没有为我执行此操作。我试图自己编码一个字符串,但这不会包含在标题中。当我传入一个数组时,它没有被编码。
这是我的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json', 'Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_URL, "http://localhost:8888/testrail/index.php?/miniapi/add_case/s2");
curl_setopt($ch, CURLOPT_POSTFIELDS, $caseArgs);//$caseArgs is an array from another function
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_exec($ch);
编辑 - - -
Here is the array that I am working with:
/*Function to set the data for each individual test case*/
function setTestCase($cellValue){
$case[]=array();
$case['title'] = $cellValue[0];
echo $case['title']. "<- Title"."<br/>";
$case['type'] = $cellValue[1];
echo $case['type']. "<- Type"."<br/>";
$case['priority'] = $cellValue[2];
echo $case['priority']. "<- Priority"."<br/>";
/*$case['estimate'] = $cellValue[3];
echo $case['estimate']. "<- Estimate"."<br/>";
$case['milestone'] = $cellValue[4];
echo $case['milestone']. "<- MileStone"."<br/>";
$case['refs'] = $cellValue[5];
echo $case['refs']. "<- Custom Refs"."<br/>";
$case['precon'] = $cellValue[6];
echo $case['precon']. "<- Custom Precondition"."<br/>";
$case['steps'] = $cellValue[7];
echo $case['steps']. "<- Custom Steps"."<br/>";
$case['expectedresults'] = $cellValue[8];
echo $case['expectedresults']. "<- Expected Results"."<br/>";
$case['testSuite'] = $cellValue[9];
echo $case['testSuite']. "<- TestSuite"."<br/>";*/
$caseData=array(
'Title'=> $case['title'],
'Type'=> $case['type'],
'Priority'=> $case['priority'],
'key'=> "246810",
);
return $caseData;
}