I figure it out! So, I needed to throw in a blank line (\r\n) at the end of the GET request inside of the POST request.
Now the question is, is this a mojolicious bug or not? Is the content inside of a multipart post request required to have a blank line after it? On Tuesday, September 18, 2018 at 1:48:07 PM UTC-4, Dan Book wrote: > > I think you missed something in my post. You should not need to add any > content length headers yourself. > > -Dan > > On Tue, Sep 18, 2018 at 1:28 PM Steve Dondley <[email protected] > <javascript:>> wrote: > >> Thanks. It doesn't look like adding the content-length helped. Still >> getting 400 errors. And I just noticed that in Google's example there is no >> content-length header for a GET request. Don't know what else to try now. >> >> On Tuesday, September 18, 2018 at 1:06:23 PM UTC-4, Dan Book wrote: >>> >>> These "parts" are essentially embedded HTTP requests; the lines under >>> each listed GET/PUT/etc are headers for that embedded request. Here is the >>> structure of their example annotated: >>> >>> POST /batch/farm/v1 HTTP/1.1 # actual request and headers >>> Authorization: Bearer your_auth_token >>> Host: www.googleapis.com >>> Content-Type: multipart/mixed; boundary=batch_foobarbaz >>> Content-Length: total_content_length >>> # rest is actual request content >>> --batch_foobarbaz # first multipart segment >>> Content-Type: application/http # multipart segment headers >>> Content-ID: <item1:[email protected]> >>> >>> GET /farm/v1/animals/pony # multipart segment *content* >>> >>> --batch_foobarbaz # second multipart segment >>> Content-Type: application/http # multipart segment headers >>> Content-ID: <item2:[email protected]> >>> >>> PUT /farm/v1/animals/sheep # multipart segment *content* >>> Content-Type: application/json >>> Content-Length: part_content_length >>> If-Match: "etag/sheep" >>> >>> { >>> "animalName": "sheep", >>> "animalAge": "5" >>> "peltColor": "green", >>> } >>> >>> --batch_foobarbaz # third multipart segment >>> Content-Type: application/http # multipart segment headers >>> Content-ID: <item3:[email protected]> >>> >>> GET /farm/v1/animals # multipart segment *content* >>> If-None-Match: "etag/animals" >>> >>> --batch_foobarbaz-- >>> >>> As noted the part where the part_content_length is is inside the content >>> for one of the multipart segments. Mojolicious doesn't have anything to >>> deal with the content of multipart segments of this type, so you need to >>> construct them yourself, but you could maybe leverage Mojolicious's >>> existing ability to construct such HTTP requests. >>> >>> my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep', >>> {'If-Match' => 'etag/sheep'}, json => $sheep_data); >>> ... >>> my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart >>> => [ >>> {content => $embedded_tx->req->to_string, 'Content-Type' => >>> 'application/http'}, >>> ... >>> ]); >>> >>> Hope that helps, >>> -Dan >>> >>> On Tue, Sep 18, 2018 at 12:50 PM Steve Dondley <[email protected]> >>> wrote: >>> >>>> I'm starting a new thread related to the previous one regarding making >>>> a batch api request to Google's API. I keep getting "Bad Reqeust" >>>> responses >>>> from Google after making a batch API call (other calls work fine). >>>> >>>> Looking at the api documentation for batch api requests >>>> <https://developers.google.com/gmail/api/guides/batch> it says each >>>> part of the multipart request should have a content length. Here is the >>>> example Google supplies: >>>> >>>> POST /batch/farm/v1 HTTP/1.1 >>>> Authorization: Bearer your_auth_token >>>> Host: www.googleapis.com >>>> Content-Type: multipart/mixed; boundary=batch_foobarbaz >>>> Content-Length: total_content_length >>>> >>>> --batch_foobarbaz >>>> Content-Type: application/http >>>> Content-ID: <item1:[email protected]> >>>> >>>> GET /farm/v1/animals/pony >>>> >>>> --batch_foobarbaz >>>> Content-Type: application/http >>>> Content-ID: <item2:[email protected]> >>>> >>>> PUT /farm/v1/animals/sheep >>>> Content-Type: application/json >>>> Content-Length: part_content_length >>>> If-Match: "etag/sheep" >>>> >>>> { >>>> "animalName": "sheep", >>>> "animalAge": "5" >>>> "peltColor": "green", >>>> } >>>> >>>> --batch_foobarbaz >>>> Content-Type: application/http >>>> Content-ID: <item3:[email protected]> >>>> >>>> GET /farm/v1/animals >>>> If-None-Match: "etag/animals" >>>> >>>> --batch_foobarbaz-- >>>> >>>> >>>> >>>> The requests I'm generating with mojolicious do not have the >>>> "part_content_length." Here's mine: >>>> >>>> POST /batch/gmail/v1 HTTP/1.1 >>>> Authorization: Bearer A_REAL_TOKEN_GOES_HERE >>>> Host: www.googleapis.com >>>> Accept-Encoding: gzip >>>> Content-Length: 120 >>>> User-Agent: Mojolicious (Perl) >>>> Content-Type: multipart/mixed; boundary=nS2CX >>>> >>>> >>>> --nS2CX >>>> Content-Type: application/http >>>> >>>> >>>> GET /gmail/v1/users/[email protected]/messages/165eb111fcf21503 >>>> --nS2CX-- >>>> >>>> >>>> >>>> My question is, does Mojolicious provide a way to automatically >>>> generate a content length header for these parts? If not, which parts of >>>> the message get counted toward this length and how do I calculate it >>>> (assuming UTF-8)? >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Mojolicious" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at https://groups.google.com/group/mojolicious. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Mojolicious" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/mojolicious. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
