dongmaomou4117 2016-09-15 05:31
浏览 86

您必须在使用Bugzilla的这部分之前登录,代码:410

I am able to get the GET request working but having issues related to authentication in POST and PUT request. I am getting the error "You must log in before using this part of Bugzilla". I have provided the correct username and password. I have tried CURLAUTH_ANY as well as CURLAUTH_BASIC. I have tried both PUT and POST request. Any help is appreciated.

   $url ="http://localhost:8080/bugzilla/rest/bug/2";
   $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, "PUT");  
  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");
 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 $result = curl_exec($ch);
 $info = curl_getinfo($ch);
 curl_close($ch); 

 echo $result
  • 写回答

1条回答 默认 最新

  • doutui2883 2016-09-16 11:29
    关注

    Following code solved my problem. I have written a blog on it which might be useful to others encountering the same problem.

           <?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)
    
        ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算