Certains démonstration de la façon d'envoyer un multipart/organisme lié à un certain site. Je ne sais pas si cela envoie exactement les données requises par l'API Google, mais cela devrait vous donner l'idée. Il est toujours recommandé d'avoir une compréhension basique de MIME, en particulier des constructions de messages multipart dans MIME (où multipart/related n'est qu'un exemple) et de Content-Transfer-Encoding. Le Wikipedia entry to MIME pourrait être un bon début pour cela.
use strict;
use warnings;
use LWP;
use MIME::Base64 'encode_base64';
use HTTP::Request;
# Create the parts, each consisting of MIME-Header and body.
my $part1 =
"Content-type: application/json; charset=UTF-8\r\n\r\n".
"some json here\r\n";
my $part2 =
"Content-type: image/gif\r\nContent-Transfer-Encoding: base64\r\n\r\n".
encode_base64("...image data here...");
# Combine the parts to a single multipart, using the boundary defined later
# in the Content-Type.
my $body =
"--some-boundary\r\n". # start of 1st part
$part1.
"--some-boundary\r\n". # start of 2nd part
$part2.
"--some-boundary--\r\n"; # end boundary
# Create the request. The Content-type is multiplart/related and defines
# the boundary used to separate the parts.
my $req = HTTP::Request->new(
POST => 'http://example.com/api/postit',
[
'Content-length' => length($body),
'Content-type' => 'multipart/related; boundary="some-boundary"',
],
$body
);
LWP::UserAgent->new->request($req);
Quel code avez-vous essayé jusqu'à présent? S'il vous plaît ajouter un [mcve] à votre question –
https://www.google.co.uk/search?q=cpan+HTTP+POST+multipart – Quentin
@Quentin Votre lien pointe vers 'multipart/form-data' pendant que j'ai besoin 'multipart/related'. – porton