我有一個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