来自 Perl 的 HTTP(S) 请求通过代理仅使用 IO::Socket [英] HTTP(S) request from Perl over proxy with IO::Socket only

查看:49
本文介绍了来自 Perl 的 HTTP(S) 请求通过代理仅使用 IO::Socket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Perl 脚本,我可以在其中向 HTTPS 服务器发出 PUT 请求并发送文件.请求仅通过 IO::Socket::SSL 完成.

I have the Perl script where i do PUT request to HTTPS server and send a file. The request is done only with IO::Socket::SSL .

$socket = new IO::Socket::INET(PeerAddr => $host,PeerPort => $port,Proto    => 'tcp');
my $h ="PUT ".$path." HTTP/1.0\r\n";
    $h.="Accept: */*\r\n";
    ........
    $h.="\r\n";

print $socket $h;

但是现在我需要通过代理服务器来做这个请求

But now i need to do this request over the proxy server

最简单的方法是什么?我可以配置 prozy 服务器来设置不同类型的连接(如果有不同的类型).什么类型最好?

How is most easy way to do this? I can configure the prozy server to set different types of connections (if there are different types). What s best type?

如何做请求?据我了解,我必须使用 IO::Socket 连接到代理并放置诸如 CONNECT 之类的东西.

How to do the request? As i understand, i have to connect to the proxy with IO::Socket and put something like CONNECT.

这看起来如何?

谢谢

更新 1.我找到了这样的解决方案 http://search.cpan.org/~oleg/IO-Socket-Socks-0.62/lib/IO/Socket/Socks.pmIO::Socket::Socks 模块满足了我的需求.但不适用于 HTTPS.我尝试使用 IO::Socket::SecureSocks.但它总是失败

Update 1. I found the solution like this http://search.cpan.org/~oleg/IO-Socket-Socks-0.62/lib/IO/Socket/Socks.pm The module IO::Socket::Socks does what i need. But not for HTTPS. I tried to use IO::Socket::SecureSocks. But it fails all time

#!/usr/bin/perl

use IO::Socket::SecureSocks;


my $socket = IO::Socket::SecureSocks->new(
              ProxyAddr   => '127.0.0.1',
              ProxyPort   => 8876,  
              ConnectAddr => 'yahoo.com',
              ConnectPort => 443,
              Timeout     => 10
              ) or die "Error $!\n";

print $socket "GET / HTTP 1.1\r\n\r\n";
print join ('',<$socket>);

显示错误.我做错了什么?

It shows error. What do i do wrong?

此代理与 PHP 和 https 链接中的 curl 配合良好.代理是SOCKS 5代理

This proxy works fine with curl in PHP and https links. The proxy is SOCKS 5 proxy

推荐答案

我自己找到了解决方案.我使用模块 IO::Socket::Socks::Wrapper 将所有请求重定向到 SOCKS5 代理.我只在脚本的开头添加了

I found the solution myself. I used the module IO::Socket::Socks::Wrapper to redirect all requests to SOCKS5 proxy. I only added on the beginning of my script

use IO::Socket::Socks::Wrapper (
{
    ProxyAddr => 'proxy.addr',
    ProxyPort => 8876,
}
);

这篇关于来自 Perl 的 HTTP(S) 请求通过代理仅使用 IO::Socket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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