What's a good way to access the bugzilla webservice from a different domain?
I have two sites 开发者_开发知识库products.company.com
and bugzilla.internal.com
. I would like to access bug information from the products.company.com page. I set up a jQuery ajax function to make a jsonrpc call to bugzilla.internal.com/jsonrpc.cgi
. However due to cross domain scripting restrictions, this was blocked by apache (as expected). So then I shot the ajax to a cgi script on products.company.com and then used curl in that script to shoot off the request to bugzilla.internal.com/jsonrpc.cgi
, but now it says
You don't have permission to access /jsonrpc.cgi
What to do?
if it makes the task any simpler, I only want to use the get bug feature.
If your web server at products.company.com is Apache, you can set up a ProxyPass.
If you can't modify web server configuration, then a simple proxy cgi at products.company.com can do the trick:
#!/usr/bin/perl
use LWP::UserAgent;
use CGI qw(:standard);
my $URL='http://bugzilla.internal.com/jsonrpc.cgi';
my $q = new CGI;
my $query = &query_string();
my $req = HTTP::Request->new(POST => $URL);
$req->content_type('application/x-www-form-urlencoded');
$req->content($query);
my $ua = LWP::UserAgent->new;
$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 $response->decoded_content;
You have a couple options. You can have products.company.com
make the request to bugzilla.internal.com
and have it basically act as a proxy.
Another option would be to use jsonp from the client - this will allow for cross domain calls. Here's a pretty good IBM article on getting started with jsonp.
There are several work arounds for cross domain scripting restrictions. I haven't tested it, but easyXDM seems to do what you want.
精彩评论