gpt4 book ai didi

Perl AnyEvent::HTTP 请求使用代理失败

转载 作者:可可西里 更新时间:2023-11-01 16:28:47 24 4
gpt4 key购买 nike

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

但是,我无法通过代理让它工作...

    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;

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

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

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

595 - 连接建立、代理握手期间出错

请帮我找出这段代码的问题。谢谢!

最佳答案

您不能将您的用户名和密码放在 $host 本身中。您需要先用 base64 手动对它们进行编码,然后将生成的字符串添加到 Proxy-Authorization header 中。

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

然后将这一行添加到您的标题中:

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 请求使用代理失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12671099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com