Php Bugzilla REST接口-如何为POST请求提供API密钥和身份验证
由于Bugzilla REST API不需要用户名/密码进行身份验证,因此我可以对其进行访问(请单击链接查看我编写的用于发出GET请求的程序)。但是,创建bug(POST请求)需要用户名和密码。我也生成了API密钥,但找不到关于如何在PHP程序中使用API密钥对Bugzilla服务器进行REST POST调用的文档。当我执行以下程序时,我得到一个错误:您必须在使用Bugzilla的这一部分之前登录,代码:410。感谢您对解决此问题的任何帮助Php Bugzilla REST接口-如何为POST请求提供API密钥和身份验证,php,json,rest,curl,Php,Json,Rest,Curl,由于Bugzilla REST API不需要用户名/密码进行身份验证,因此我可以对其进行访问(请单击链接查看我编写的用于发出GET请求的程序)。但是,创建bug(POST请求)需要用户名和密码。我也生成了API密钥,但找不到关于如何在PHP程序中使用API密钥对Bugzilla服务器进行REST POST调用的文档。当我执行以下程序时,我得到一个错误:您必须在使用Bugzilla的这一部分之前登录,代码:410。感谢您对解决此问题的任何帮助 $url ="http://localh
$url ="http://localhost:8080/bugzilla/rest/bug";
$apikey = "IZC4rs2gstCal0jEZosFjDBRV9AQv2gF0udh4hgq";
$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,$str_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 = "abbincrc";
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
$result = curl_exec($ch);
curl_close($ch);
echo $result
下面是为我工作并解决我的问题的代码。我把它贴在这里,以便对其他人有用。我也有
,如问题所述,它使用的是XMLRPC API,而不是REST API。
<?php
$url = 'http://localhost:8080//bugzilla/xmlrpc.cgi';
$ch = curl_init();
$header = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt_array($ch, $header);
$bugreport = array(
'login' => 'ashish.sureka@in.abb.com',
'password' => 'abbincrc',
'product' => "TestProduct",
'component' => "TestComponent",
'summary' => "Bug Title : A One Line Summary",
'assigned_to' => "ashish.sureka@in.abb.com",
'version' => "unspecified",
'description' => "Bug Description : A Detailed Problem Description",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $bugreport);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch)
?>