Created
August 31, 2010 22:30
-
-
Save redneb/559889 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use URI; | |
| use IO::Socket::INET; | |
| sub chunk { | |
| my $data = shift; | |
| $data = '' unless defined $data; | |
| my $output = sprintf '%x', length($data); | |
| $output .= "\r\n"; | |
| $output .= $data; | |
| $output .= "\r\n" if length($data); | |
| return $output; | |
| } | |
| unless (defined $ARGV[0]) { | |
| print "Usage:\n $0 URL\n"; | |
| exit 0; | |
| } | |
| my $uri = URI->new($ARGV[0]); | |
| my $output = ''; | |
| # headers | |
| $output .= 'POST ' . $uri->path_query . " HTTP/1.1\r\n"; | |
| $output .= 'Host: ' . $uri->host . ($uri->_port ? ':' . $uri->_port : '') . "\r\n"; | |
| $output .= "Connection: close\r\n"; | |
| $output .= "Content-Type: text/plain\r\n"; | |
| $output .= "Transfer-Encoding: chunked\r\n"; | |
| $output .= "\r\n"; | |
| # chunk 1 | |
| $output .= chunk('ABCDEFGHIJKL'); | |
| # chunk 2 | |
| $output .= chunk('MNOPQRSTUVWXYZ'); | |
| # last chunk | |
| $output .= chunk; | |
| # trailer | |
| #$output .= "Name: value\r\n"; | |
| # terminate chunked stream | |
| $output .= "\r\n"; | |
| # send $output to the server | |
| my $sock = IO::Socket::INET->new($uri->host_port); | |
| print $sock $output; | |
| # print raw response | |
| print <$sock>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment