http://qs1969.pair.com?node_id=1159412

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

Hi all, I have a simple script to POST data, but for some reason it is not posting the data:
#!/usr/bin/perl use strict; use LWP::UserAgent; use MIME::Base64; use JSON; my $ua = LWP::UserAgent->new; push @{ $ua->requests_redirectable }, 'POST'; my $server_endpoint = "http://photos.mysite.com/api/1/upload/"; my $server_api_key = "xxxx"; my $encoded = "http://photos.mysite.com/128.jpg"; my $req = HTTP::Request->new(POST => $server_endpoint); #$req->header('content-type' => 'multipart/form-data'); $req->header('content-type' => 'application/json'); my $post_json = { key => $server_api_key, source => $encoded, format => "json", }; my $post_data = encode_json($post_json); $req->content($post_data); printf "\n\n$post_data\n"; my $resp = $ua->request($req); print $resp->as_string; if ($resp->is_success) { my $message = $resp->decoded_content; print "Received reply: $message\n"; } else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; }
Response in web server logs:
192.168.1.108 - - [03/Apr/2016:19:22:43 +1000] "POST /api/1/upload/ HT +TP/1.1" 301 424 "-" "libwww-perl/6.08"
You can see that the data is not being posted? I would expect to see something like: (which works when I use the Paw Client to do the POST)
192.168.1.54 - - [03/Apr/2016:19:32:44 +1000] "POST /api/1/upload/?key +=xxxx&format=json&source=http%3A%2F%2Fphotos.mysite.com%2F128.jpg HTT +P/1.1" 200 2570 "-" "Paw/2.3.3 GCDHTTPRequest"
Any ideas would be greatly appreciated. Thanks, HW