#!/usr/bin/perl -- use strict; use warnings; use JSON; use LWP; my $endpoint = URI->new("https://indexing.googleapis.com/batch"); use HTTP::Request::Common(); my $base_request = HTTP::Request::Common::POST( $endpoint, Authorization => "Bearer TOKEN", Content_Type => 'multipart/mixed', ); $base_request->add_part( BlaFoo({ url => 'http://example.com/1', type => "URL_UPDATED" }), BlaFoo({ url => "http://example.com/2", type => "URL_UPDATED" }) ); print $base_request->as_string; exit 0 ; sub BlaFoo { return SnaFoo( POST => "/v3/urlNotifications:publish", ## todo? Content_Type => 'application/json', Accept => 'application/json', Content => encode_json( shift ) ); } sub SnaFoo { my $req = HTTP::Message->new; my $content; $content = shift if @_ and ref $_[0]; my($k, $v); while (($k,$v) = splice(@_, 0, 2)) { if (lc($k) eq 'content') { $content = $v; } else { $req->push_header($k, $v); } } $req->header('Content-Length' => length($content)) unless ref($content); $req->content($content); $req = HTTP::Message->new( undef, $req->as_string ); $req->header( 'Content-Type' => 'application/http' ); $req->header( 'Content-Transfer-Encoding' => 'binary' ); $req->header( 'Content-ID' => '' ); ## todo? return $req; } __END__