4

A post request is made to:

http://www.example.com/example/

and the post data is as follows:

------WebKitFormBoundaryB8NNdk2kNdndnnn
Content-Disposition: form-data; name="picture[uploaded_data]"; filename="picture.jpg"
Content-Type: image/jpeg

binarydatagoeshere
------WebKitFormBoundaryB8NNdk2kNdndnnn--

So my question is, how can i use curl to do this exact same thing with the binary data of picture.jpg? I know of --data-binary @myfile.bin, but this is completely different and in this case the string after Boundary e.g B8NNdk2kNdndnnn in this case needs to be valid for the request to go through. So how do i do all this using curl?

0

2 Answers 2

1

I think the --form option should do what you need:

curl --form "picture[uploaded_data][email protected];type=image/jpeg" http://www.example.com/example/
0

This is a sample script in to POST multipart. You need to adapt it a bit :

#!/usr/bin/env perl

use strict; use warnings;
use WWW::Mechanize;

my $m = WWW::Mechanize->new(
    autocheck => 1,
    agent_alias => 'Mozilla',
    cookie_jar => {},
    ssl_opts => {verify_hostname => 0},
    quiet => 0,
);
$m->get("http://domain.tld");                                                   

$m->post('https://domain.tld/send',
    Content_Type => "form-data",
    Content => [
        'picture[uploaded_data]' => 'foobar',
        file => [ '/path/to/image', 'image_name', 'Content-Type' => 'image/jpeg' ]
    ]
);

print $m->content;

Check http://search.cpan.org/~gaas/HTTP-Message-6.06/lib/HTTP/Request/Common.pm

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.