2013-01-22 30 views
1

我想用Perl發佈數據到頁面,但是頁面也需要標題。我將如何發佈標題和發送標題(餅乾,用戶代理等)?用Perl中的請求標題發佈到網頁

我嘗試使用LWP::UserAgent,但我無法弄清楚如何發送標題,即使我可以發佈到頁面。

關於此主題還有一件事。當我在該頁面上發佈並打印響應內容時,我可以看到html很好,除了應該顯示的數字外。

回答

2

嘗試這樣做:

use LWP::UserAgent; 
use HTTP::Request; 

my $userAgent = LWP::UserAgent->new(); 
my $request = HTTP::Request->new(
    POST => "http://domain.tld/path" 
); 
$request->content("stuff=foobar"); 
$request->content_type("application/x-www-form-urlencoded"); 
my $response = $userAgent->request($request); 

if ($response->code == 200) { 
    print $response->as_string; 
} 
else { 
    die $response->status_line; 
} 
+0

謝謝,我會試試看。 – Grigor

+0

$ userAgent未定義。請修復答案。 – Grigor

+0

POST編輯並測試確定。 –