2016-09-14 12 views
0

GET Request(私がGETリクエストを作成するためのリンクをクリックしてください)をBugzilla REST APIにすることができます認証にユーザー名/パスワードは必要ありません。ただし、バグ(POSTリクエスト)を作成するには、ユーザー名とパスワードが必要です。 APIキーも生成しましたが、PHPプログラム内からAPIキーを使用してBugzillaサーバーへのREST POST呼び出しを行う方法に関するドキュメントは見つかりませんでした。次のプログラムを実行すると、エラーが発生します。この部分を使用する前に、Bugzilla。code:410にログインする必要があります。問題を解決するための助けをいただければ幸いです。Bugzilla RESTインターフェイス - APIリクエストを受け取るためにAPIキーを提供する方法

 $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 = "[email protected]"; 
     $password = "abbincrc"; 
     curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password); 
     $result = curl_exec($ch); 
     curl_close($ch); 

     echo $result 

答えて

0

以下は私のために働いて問題を解決したコードです。私はそれを他の人にも役立つようにここに掲示しています。また、私はwritten a blog on itを持っています。

 <?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'  => '[email protected]', 
      'password' => 'abbincrc', 
      'product'  => "TestProduct", 
      'component' => "TestComponent", 
      'summary'  => "Bug Title : A One Line Summary", 
      'assigned_to' => "[email protected]", 
      '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) 

     ?> 
関連する問題