Perl AnyEvent :: HTTP请求使用代理失败 [英] Perl AnyEvent::HTTP request using Proxy fails

查看:149
本文介绍了Perl AnyEvent :: HTTP请求使用代理失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过以下帖子使用perl模块AnyEvent :: HTTP发出异步HTTP请求: http://www.windley.com/archives/2012/03/asynchronous_http_requests_in_perl_using_anyevent.shtml

I tried using the perl module AnyEvent::HTTP to make asynchronous HTTP requests by following this post: http://www.windley.com/archives/2012/03/asynchronous_http_requests_in_perl_using_anyevent.shtml

但是,我无法通过代理对其进行操作...

However, I'm not able to get it working through proxies...

    my $request;
    my $host = '<userid>:<pswd>@<proxyip>';
    my $port = '<proxyport>';
    my $headers = { ...                        
                    'Accept-Language'=> 'en-us,en;q=0.5',
                    'Accept-Charset'=> 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                    'Keep-Alive' => 300,
                    };

    $request = http_request(
      GET => $url,
      timeout => 120, # seconds
      headers => $headers,
      proxy => [$host, $port],
      mymethod
   );

$cv->end;
$cv->recv;    

我在使用上面的代码替换代理身份验证详细信息后收到以下错误

I get the following error for the above code (after substituting with authentication details for the proxy)

   { 
      'Reason' => 'No such device or address',
      'URL' => 'www.google.com',
      'Status' => 595
    };

在没有请求的proxy参数的情况下,它可以工作.在CPAN页面 http://metacpan.org/pod/AnyEvent::HTTP 中,

Without the proxy argument of the request, it works. From the CPAN page http://metacpan.org/pod/AnyEvent::HTTP,

595-建立连接时发生错误,代理握手

595 - errors during connection establishment, proxy handshake

请帮助我确定此代码存在的问题.谢谢!

Please help me identify the problem with this code. Thanks!

推荐答案

您不能将用户名和密码放在$ host本身中.您首先需要手动在base64中对它们进行编码,然后将结果字符串添加到Proxy-Authorization标头中.

You cant put your username and password in the $host itself. You need to first encode them in base64 by hand and add the resulting string in the Proxy-Authorization header.

$ echo -n user:pass | openssl enc -a
dXNlcjpwYXNz

然后将此行添加到标题:

Then add this line to your header:

my $request;
my $host = '<proxyip>'; #EDITED 
my $port = '<proxyport>';
my $headers = { ...                        
                'Accept-Language'=> 'en-us,en;q=0.5',
                'Accept-Charset'=> 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                'Keep-Alive' => 300,
                'Proxy-Authorization'=>'Basic dXNlcjpwYXNz' #EDITED
                };

$request = http_request(
  GET => $url,
  timeout => 120, # seconds
  headers => $headers,
  proxy => [$host, $port],
  mymethod

那应该可以了!

这篇关于Perl AnyEvent :: HTTP请求使用代理失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆