Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Bugzilla REST接口-如何为POST请求提供API密钥和身份验证_Php_Json_Rest_Curl - Fatal编程技术网

Php Bugzilla REST接口-如何为POST请求提供API密钥和身份验证

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

由于Bugzilla REST API不需要用户名/密码进行身份验证,因此我可以对其进行访问(请单击链接查看我编写的用于发出GET请求的程序)。但是,创建bug(POST请求)需要用户名和密码。我也生成了API密钥,但找不到关于如何在PHP程序中使用API密钥对Bugzilla服务器进行REST POST调用的文档。当我执行以下程序时,我得到一个错误:您必须在使用Bugzilla的这一部分之前登录,代码:410。感谢您对解决此问题的任何帮助

       $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)

      ?>