hprince has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm trying to post a registration form to an HTTPS form through a socks proxy, but I've run into some problems.

I get...

'Bad arg length for Socket6::unpack_sockaddr_in6, length is 16, should be 28 at /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level/Socket6.pm line 282, <STDIN> line 5.'

...when I run this code:
use LWP::UserAgent; use LWP::Protocol::socks; use HTTP::Request; my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows + NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5'); $ua->proxy([qw(http https)] => "socks4://xx.xx.xx.xx:1080"); $ua->ssl_opts( verify_hostnames => 0 ); my $user_form_data = ["user"=>"$username", "pass"=>"$password", "passc +heck"=>"$password"]; my $response = $ua->post("https://ssl.xxxxxx.com/post/register",$user_ +form_data); die "Error: ", $response->status_line . "\n" unless $response->content;

I've seen a bit about this error online, but nothing that is clear. This code works fine with GET requests via HTTP (not HTTPS).

Also, I'm not sure if I need an ENV proxy variable entered, but, if I do, there is another problem: I have to change proxies halfway through the script and connect to another server.

Any ideas would be GREATLY appreciated!

Many thanks in advance,

Henry

Replies are listed 'Best First'.
Re: HTTPS POST with LWP via Socks
by noxxi (Pilgrim) on Apr 27, 2014 at 19:02 UTC
    Interesting problem.
    LWP is using IO::Socket::SSL as backend for https which transparently uses IPv6 if available. But, with plain http LWP is only using IPv4 (Net::HTTP isa IO::Socket::INET).
    Your SSL host probably resolves to an IPv6 address so IO::Socket::SSL will use it, but then you try this address with a socks4 proxy - and the socks4 protocol can only do IPv4.

    So what can you do?
    • use an Socks5 proxy in the hope that LWP::Protocol::https supports IPv6
    • restrict IO::Socket::SSL to IPv4 by loading it with use IO::Socket::SSL 'inet4'. Note, that this must be done on the first import, e.g. perl -MIO::Socket::SSL=inet4 yourprogram.pl
    • you might also try to enforce IPv4 with @LWP::Protocol::http::EXTRA_SOCK_OPTS=( Family => AF_INET );