【发布时间】:2016-09-13 14:34:56
【问题描述】:
执行 PHP 脚本后,我收到以下错误 - 感谢任何帮助。根据我的理解,我根据 bugzilla 文档创建了一个数组 - 提前致谢
https://bugzilla.readthedocs.io/en/5.0/api/core/v1/bug.html#create-bug
{"code":32000,"error":true,"message":"无法将 '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 = 'ashish.sureka@in.abb.com';
$password = 'incrc';
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
$result = curl_exec($ch);
curl_close($ch);
echo $result
【问题讨论】:
-
当您使用键
summary从$data数组中的值中删除单引号时,是否仍然会出现这种情况? -
感谢您的关注。我删除了单引号 ' 但仍然遇到同样的错误
-
您不应该将
$str_data用于您的 POSTFIELDS 参数吗?