我有一个Perl脚本通过REST API备份我们的TeamCity服务器,如下所示:Perl的HTTP POST请求失败,TeamCity的REST API
use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw{ POST GET }
# ... code ommitted for brevity ... #
my $url = 'http://teamcity:8080/httpAuth/app/rest/server/backup';
my $req = POST($url . '?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=' . $filename);
$req->authorization_basic($username, $password);
my $resp = $ua->request($req);
我试图与文档发布内容更加符合HTTP:请求,但由于某种原因失败了,抱怨我没有指定一个文件名:
# This fails
my $req= POST($url, [ 'includeConfigs' => 'true',
'includeDatabase' => 'true',
'includeBuildLogs' => 'true',
'fileName' => $filename,
]);
然而,当我看到在后端REST日志TeamCity的,完整的请求似乎已经使它完好无损,与上面通过的一样。
登录成功命令:
[2012-12-13 15:02:38,574] DEBUG [www-perl/5.805 ] - rver.server.rest.APIController - REST API request received: POST '/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=foo', from client 10.126.31.219, authenticated as jsmith
登录失败的命令:
[2012-12-13 14:57:00,649] DEBUG [www-perl/5.805 ] - rver.server.rest.APIController - REST API request received: POST '/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=foo', from client 10.126.31.219, authenticated as jsmith
有没有做一个POST请求,可能是导致故障的两种方法之间的任何其他隐藏的区别?
UPDATE:下面是每个请求的结果通过数据::自卸车打印时
成功POST:
$VAR1 = bless({
'_content' => '',
'_uri' => bless(do{\(my $o = 'http://teamcity:8080/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=foo')}, 'URI::http'),
'_headers' => bless({
'content-type' => 'application/x-www-form-urlencoded',
'content-length' => 0,
'authorization' => 'Basic c3lzQnVpbGRTeXN0ZW1JOnBhaWQuZmFpdGg='
}, 'HTTP::Headers'),
'_method' => 'POST'
}, 'HTTP::Request');
不成功POST:
$VAR1 = bless({
'_content' => 'includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=foo',
'_uri' => bless(do{\(my $o = 'http://teamcity:8080/httpAuth/app/rest/server/backup')}, 'URI::http'),
'_headers' => bless({
'content-type' => 'application/x-www-form-urlencoded',
'content-length' => 75,
'authorization' => 'Basic c3lzQnVpbGRTeXN0ZW1JOnBhaWQuZmFpdGg='
}, 'HTTP::Headers'),
'_method' => 'POST'
}, 'HTTP::Request');
这里没有东西加起来。你确定第一个日志条目真的对应于失败的命令吗?尝试在失败的命令中使用可识别的内容,如不同的文件名,并查看它是否生成您期望的日志条目。 – dan1111
如果你只能看到有多少头发已经从我的脑海中抽出来,并且检查和重复检查相同... ;-)日志输出仅显示TeamCity声明已收到的请求URI ......所以必须有一些更细微的差异。 – RCross
只是为了澄清:你使用'HTTP :: Request :: Common'? – dan1111