简体   繁体   English

如何配置WWW :: Mechanize在代理和https之后工作?

[英]How do I configure WWW::Mechanize to work behind a proxy and https?

I've written Perl code using WWW::Mechanize to retrieve a webpage. 我已经使用WWW :: Mechanize编写了Perl代码来检索网页。 When I retrieve http webpages it works fine but it doesnt work for https. 当我检索http网页时,它工作正常,但不适用于https。 I've checked and I have the Crypt::SSLeay package. 我已经检查过,并且拥有Crypt :: SSLeay软件包。 What else could be wrong? 还有什么可能是错的?

The error message is.. 错误消息是..

Error GETing https://www.temp.com: Can't Connect to www.temp.com:443 <Bad hostname 'www.temp.com'> at scrape.pl line 8

I've seen in your related Mechanize question that you call the proxy method with only the http and ftp schemes. 我在您相关的Mechanize问题中看到, 仅使用httpftp方案调用proxy方法 Try again with https included. 包含https然后重试。

It's probably more useful to set up the proxy environment variables since then all programs can take advantage of this central configuration instead of configuring proxies for each program separately. 设置代理环境变量可能更有用,因为这样所有程序都可以利用此中央配置,而不必分别为每个程序配置代理。 Do not forget https_proxy . 不要忘记https_proxy Call the env_proxy method instead of proxy to use them. 调用env_proxy方法而不是proxy来使用它们。

Apparently, I needed to add the following in my file 显然,我需要在文件中添加以下内容

$ENV{'HTTPS_PROXY'} = 'http://proxy:port/';

for Crypt::SSLeay 用于Crypt :: SSLeay

In case someone stumbles over this old question: The situation has changed in the recent years. 如果有人偶然发现了这个老问题:近年来情况发生了变化。

  • starting with version 6 LWP uses IO::Socket::SSL as a backend 从版本6开始LWP使用IO :: Socket :: SSL作为后端
  • IO::Socket::SSL does not provide its own proxy hacks like Crypt::SSLeay does and LWP https proxy support as documented (eg using proxy method or env_proxy) was broken. IO :: Socket :: SSL不像Crypt :: SSLeay那样提供自己的代理黑客,并且记录的LWP https代理支持(例如,使用代理方法或env_proxy)已损坏。
  • with version 6.06 of both LWP::UserAgent and LWP::Protocol::https (which are now seperate distributions!) https proxy works as expected and documented 使用LWP :: UserAgent和LWP :: Protocol :: https 6.06的版本(现在是单独的发行版!)https代理可以正常工作并记录在案
  • for older versions of LWP one can use Net::SSLGlue::LWP 对于较旧版本的LWP,可以使用Net :: SSLGlue :: LWP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM