#!/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"; } #### 192.168.1.108 - - [03/Apr/2016:19:22:43 +1000] "POST /api/1/upload/ HTTP/1.1" 301 424 "-" "libwww-perl/6.08" #### 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 HTTP/1.1" 200 2570 "-" "Paw/2.3.3 GCDHTTPRequest"