Perl Http处理模块大比拼
HTTP协议是目前世界上最主流的应用协议,Perl对其的支持也是空前的友好,有网友收集整理了在cpan上存在http处理模块,将它们做了对比给出在不同的情况下的使用建议。CPAN modules for making HTTP requests
This article is a review of 20 CPAN modules that can be used to make HTTP requests. Many of the modules can handle FTP and other types of requests, but here I'm just focussing on HTTP, and in particular GET and POST requests.
本文回顾了可以用来处理HTTP请求近20个 CPAN模块。许多模块可以处理FTP和其他类型协议的请求,但在这里我只是关注HTTP、特别是GET和POST请求。
If you're thinking "Sheesh, just tell me what module to use!", here's a concise summary of the recommendations:
A sensible default choice would be HTTP::Tiny: it handles all requests types, supports SSL, transparently handles redirects, and has a relatively small number of dependencies.
一个合理的默认选择将HTTP::Tiny:它处理所有请求类型,支持SSL,透明地处理重定向,并且有相对较少的依赖关系。
If you're working with cookies or need full access to the request and/or response, and top performance and minimal dependencies aren't requirements, then use LWP (or Mojo::UserAgent if you're already using Mojolicious).
如果您正在使用cookie或需要完整的访问请求和/或响应,如果不考虑依赖关系,着重最高性能和最小依赖,可以使用LWP(或Mojo::UserAgent如果你已经使用Mojolicious)。
If speed is critical for you, then you have two choices: for pure perl, go with Furl. If you're happy to install libcurl (a C library), then go for one of the Curl-based modules. LWP::Curl has the simplest interface.
如果速度是至关重要的,那么你有两种选择:纯perl,如果你乐意安装libcurl(C库),然后去Curl-based模块之一。LWP::Curl有最简单的接口并有最好的性能。
If you need speed and complete control, then look at WWW::Curl or Net::Curl.
如果你需要速度和完全控制兼得,那么可以考虑WWW::Curl或Net::Curl。
在http应用中,有如下的需求是要考虑的。In comparing the modules, I'm looking at the following:
Does it provide a clean simple interface?
Can you make https requests?
Which HTTP verbs/methods are supported?
If you want more control and information on the response, can you get it?
(How) does it handle redirects?
Support for cookies.
What dependencies does it have? I don't like to see modules that reinvent wheels just to minimise dependencies, but on the other hand if I'm relying on this module, I don't want half of CPAN pulled in.
Can you specify the User-Agent string? If you're just writing a quick script making one-off HTTP requests, you'll probably be happy to go with the module's default. But if you're writing a module, or more involved application, you'll want to stamp your own identity.Quality of documentation.
文章在逐个介绍了各个模块的使用方法,在"Comparison"节给出了较为详细的比较(功能、性能、依赖关系),在"Conclusion"节给出了使用建议。
参考来源:http://neilb.org/reviews/http-requesters.html