in reply to Help with add_part in HTTP::Message for making Batch HTTP requests for Google API

Here's example code that generates a request minus those extra set of headers

Ugh. Its a request within a request within a request. Its not hard. You dont have to involve LWP until you have to involve it.

This is almost but not quite it

#!/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($con +tent); $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' => '<b29c5de2-0db4-490b-b421-6a51b598bd +22+2>' ); ## todo? return $req; } __END__
  • Comment on Re: Help with add_part in HTTP::Message for making Batch HTTP requests for Google API
  • Download Code