There's too much hand-waving (or ellipses) to answer with code. But try it yourself.
server.pl
#! /usr/bin/perl
use warnings;
use strict;
use Plack::Builder;
use Plack::Request;
use Data::Dumper;
my $APP = sub {
my ($env) = @_;
my $req = 'Plack::Request'->new($env);
[200, [], [Dumper($req)]]
};
builder {
mount '/' => $APP;
};
client.pl
#!/usr/bin/perl
use warnings;
use strict;
use Encode;
use Digest::SHA;
use MIME::Base64 qw{ encode_base64 };
use LWP::UserAgent;
my $ua = 'LWP::UserAgent'->new;
my $url = 'http://localhost:5000';
my $str = 'hello'; # no special chars, 1-127
my $sha256 = Digest::SHA::sha256('abc123'); # bytes 0-255
my $hmac = Digest::SHA::hmac_sha512('a message', 'a key'); # bytes 0-2
+55
my $unicode_string = "\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTE
+R BETA}ab123"; # unicode chars mixed with lower-ascii
my $buffer = ""; # buffer to concatenate above into and POST them
for($str, $sha256, $hmac, $unicode_string){
$buffer .= Encode::encode('UTF-8', $_);
}
my $b64 = encode_base64($buffer);
my @HTTPHeader = (ABC => $b64);
my $response = $ua->post($url, @HTTPHeader, Content => $b64); # <-- C
+hange to your liking.
use Data::Dumper; print Dumper $response->content;
...
Now, run the server in one terminal and the client in another.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.