执行PHP脚本后,我收到以下错误 - 任何帮助表示赞赏。根据我的理解,我创建了基于Bugzilla的文档上的阵列 - 在此先感谢无法将'params'参数解析为有效的JSON(PHP,cURL,REST)
https://bugzilla.readthedocs.io/en/5.0/api/core/v1/bug.html#create-bug
{“代码”:32000,“错误”:真实的,“消息”:“无法解析” PARAMS'的说法是有效的JSON错误:格式不正确的数量(初始减后没有数字),在字符偏移1
$url ="http://localhost:8080/bugzilla/rest/bug";
$data = array(
"product" => "TestProduct",
"component" => "TestComponent",
"version" => "unspecified",
"summary" => "'This is a test bug - please disregard",
"alias" => "SomeAlias",
"op_sys" => "All",
"priority" => "P1",
"rep_platform" => "All"
);
$str_data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json", "Accept: application/json"));
$username = '[email protected]';
$password = 'incrc';
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
$result = curl_exec($ch);
curl_close($ch);
echo $result
当您使用键“摘要”从'$ data'数组中删除单引号时,这仍然会发生吗? – RichardBernards
感谢您的注意。我删除了单引号',但仍然得到相同的错误 – user1468768
,如果你不使用'$ str_data'你POSTFIELDS参数? – YvesLeBorg