'Curl create a big post request
I need to investigate a timeout problem on the server and need to make a large HTTP post request. Is there some easy way of creating a large HTTP post request with curl or are there some better tools out there.
curl -X POST -d {10mb random string} localhost:8080/test
Solution 1:[1]
Create a file of 10M
dd if=/dev/urandom of=output.dat bs=1M count=10
Then send the file using Curl
curl -X POST -d @output.dat localhost:8080/test
Is this what you are looking for?
From manpage:
-d, --data
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
--data-raw is almost the same but does not have a special interpretation of the @ character. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode.
If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'.
If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with -d, --data @foobar. When --data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don't want the @ character to have a special interpretation use --data-raw instead.
See also --data-binary and --data-urlencode and --data-raw. This option overrides -F, --form and -I, --head and --upload.
Solution 2:[2]
Here's how you can create a random file of ASCII test:
base64 /dev/urandom | head -c 5000 > output.txt
This creates a 5000 byte file.
Then pass it like the other answer:
curl -X POST -d @output.txt localhost:8080/test
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lars1595 |
| Solution 2 | user2233706 |
