簡體   English   中英

如何安裝 LWP::Protocol::https?

[英]How can I install LWP::Protocol::https?

我創建了一個 Perl 腳本來運行 https 任務。 當我運行它時,我收到錯誤LWP::Protocol::https not installed。

我無法弄清楚或找到有關如何安裝LWP::Protocol::http的教程或命令。 任何人都知道如何安裝它? 安裝LWP非常簡單。

我已經安裝了LWP並安裝了Crypt-SSLeay ,但是我仍然收到錯誤消息。 這是我的代碼:

use LWP::UserAgent;

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


# set custom HTTP request header fields

my $req = HTTP::Request->new(PUT => "https://thesite.com");

$req->header('Authorization' => 'myauth');
$req->header('Accept' => 'JSON:Application/JSON');
$req->header('Content-Type' => 'JSON:Application/JSON');
$req->header('Host' => 'api.thesite.com');

$req->content('Text' => 'thetext');



my $resp = $ua->request($req);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP POST error code: ", $resp->code, "\n";
    print "HTTP POST error message: ", $resp->message, "\n";
}

sudo yum install perl-LWP-Protocol-https為我解決了問題。

運行sudo cpan install LWP::Protocol::https為我解決了這個問題。

在@INC 中找不到 LWP/Protocol/https.pm(@INC 包含:/etc/cxs /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/ share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) 在(eval 5)第 2 行。

cpan -i LWP::Protocol::https

很久以前, LWP支持 HTTPS。 然后,在 6.02(2011 年)中,他們拆分了LWP::Protocol::https 如果您的程序是在一個古老的系統上設置的,並且您已升級,則此更改可能會絆倒您。

由於 Perl 沒有開箱即用的 SSL 支持,因此缺少它所需要的協議助手是沒有意義的(請記住,HTTPS 無處不在,那時還沒有那么普遍)。 作為一個單獨的模塊,更容易設置所有內容。

現在,訣竅就在這里。 LWP::Protocol::https需要IO::Socket::SSL需要Net::SSLeay需要openssl 如何安裝取決於你,如果你的平台有一個現成的包,那可能是最好的(因為如果你知道你不想要那個,你就不太可能問你的問題)。

如果您想自己完成整個鏈條,請從 [openssl](( https://www.openssl.org ) 開始。排序后,您可以安裝所需的模塊,其余的先決條件將得到照顧他們自己:

# ... install openssl, set env vars if in a nonstandard location
% cpan LWP::Protocol::https

附帶說明一下,舊的 Perl 實踐不包括使用您知道依賴的所有模塊。 在這種情況下,您以前沒有聲明對LWP::Protocol::https的依賴,因為您知道它隨LWP 現在,即使您知道某些模塊來自同一個發行版,也最好明確聲明您需要的所有內容。 也許在未來的某個時候,它們將處於不同的分布中。

盡管我現在將Mojo::UserAgent用於所有這些,但即使LWP在內部處理所有這些,我也會添加顯式依賴項。 這使得靜態分析更容易一些:

use LWP;
use LWP::Protocol::https;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM