rakyll / hey

HTTP load generator, ApacheBench (ab) replacement
Apache License 2.0
18k stars 1.19k forks source link

How to send form data? #210

Open Iamlovingit opened 4 years ago

Iamlovingit commented 4 years ago

Hi, I'm a newer. I know how to send a request by curl, the command is :

curl http://example.com/test \
-F "image_best=@/root/cqs/1.jpg" \
-F "image_idcard=@/root/cqs/2.jpg"

How I can send this request by hey ?

etravelstead commented 4 years ago

Same question I have. Trying to send PUT request with form-data as body.

pharrellyhy commented 4 years ago

Hi, guys,

Here is how I send both json and image data to my server.

My data file named post_data.txt contains:

--db7c097185310d799ace6ee193ebad21
Content-Disposition: form-data; name="params"
Content-Type: application/json
Connection: keep-alive

# your json file
{"device": "load_test", "device_id": "test_device"}

--db7c097185310d799ace6ee193ebad21
Content-Disposition: form-data; name="image"; filename="predict.jpg"
Content-Type: application/jpeg
Content-Transfer-Encoding: base64

# your image in base64 format 
/9j/4AAQSkZJRgABAQAAAQABAAD

--db7c097185310d799ace6ee193ebad21--

Here is how to send that file using Hey:

hey -c 250 -z 20s -m POST -H "Content-Type: multipart/form-data; boundary=db7c097185310d799ace6ee193ebad21" -T "multipart/form-data" -D post_data.txt http://localhost:5000/test_api

Change the boundaries to whatever you like, but keep them same in both txt file and in command line.

etravelstead commented 4 years ago

Thank you for answering this, is there a proper way to generate the post_data.txt file?

This is what my post-data.txt looks like. Note that I am not attaching any file, its just a single field named url with a text value

--------------------------838325931917102083820201
Content-Disposition: form-data; name="url"
https://images.macrumors.com/t/zvnKwl-GJ5QymRBy0VZG1pK9CEw=/800x0/article-new/2017/11/crying-tears-of-joy-emoji-250x248.jpg
--838325931917102083820201--

here's what my request looks like

hey -m PUT -c 10 -n 100 \
   -H "Content-Type: multipart/form-data; boundary=-----------------------------20480547701538810824208757955" \
   -H "B-Authorization:`cat token`" \
   -D post-data.txt \
   http://localhost:8099/v0/users/161/photo

I am getting multipart: NextPart: EOF on my backend service.

pharrellyhy commented 4 years ago

@etravelstead Hi, you are trying to send that url to your backend and you read the image at your backend. Is that what you want?

s15-coder commented 2 years ago

@pharrellyhy that's exactly what I need, do you know how to do it?