【问题标题】:bugzilla webservice does bug.get require authentication?bugzilla webservice bug.get 需要身份验证吗?
【发布时间】:2011-07-11 13:49:11
【问题描述】:

我正在使用 jsonrpc 访问 bugzilla webservice 的 bug.get 功能,但它正在返回:

错误:403
禁止的内容类型:text/xml
没有数据。

我对我的服务器进行 ajax 调用,然后它充当代理并向 bugzilla 网络服务(位于单独的域中)发送 POST 请求。

var obj={
    'method':'Bug.get',
    'params':{
        'id':bug_list
    },
    'id':bug_list
};
var message=$.toJSON(obj);

$.ajax({
    "contentType":"application/json",
    "data": message,
    "dataType": "json",
    "url": "bug_reply.cgi",
    "type": "post",
    error: function(d, ts, er){
        console.log("OH WOE! D: D: D: D: D: D: D: D: D:"+d+' '+ts+' '+er);
    },
    success: function(d, ts){
        console.log(d);
    }
});

cgi:

#! /usr/bin/perl

use strict;

use lib qw(.);
use CGI qw(:standard Vars);
use vars qw($cgi $template $vars);

use Bug;
use Bugzilla;
use Bugzilla::Search;
use JSON::XS;
use LWP::UserAgent;
use CGI qw(:standard);


# Include the Bugzilla CGI and general utility library.
require "CGI.pl";

my $ua = LWP::UserAgent->new;


my %form = Vars();
if($ENV{REQUEST_METHOD} eq "POST")
{
    my $URL='http://bugs1.eng.proofpoint.com/bugzilla-3.6.4/jsonrpc.cgi';

    my $q = new CGI;
    #my $query =
    my $data=$form{'POSTDATA'};

    my $req=HTTP::Request->new(POST=>$URL);
    $req->content_type('application/x-www-form-urlencoded');
    $req->content($data);

    my $ua = LWP::UserAgent->new;
    my $res = $ua->request($req);

    if ($res->is_success) {
        printf "Content-Type: %s\n\n", $res->header('Content-Type');
        print $res->content;
    } 
    else {
        printf "Content-Type: text/plain\n\n";
        print "Error: " . $res->status_line . "\n";
    }

    print $cgi->header(-type => 'text/xml');
    print $res->decoded_content;
}

【问题讨论】:

    标签: ajax web-services perl cgi bugzilla


    【解决方案1】:

    我只是用 curl 代替,它起作用了。

    【讨论】:

      猜你喜欢
      • 2011-11-17
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      • 2021-10-10
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      相关资源
      最近更新 更多