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__

In reply to Re: Help with add_part in HTTP::Message for making Batch HTTP requests for Google API by Anonymous Monk
in thread Help with add_part in HTTP::Message for making Batch HTTP requests for Google API by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.