I’ve searched for this answer but not found anything that works or that completely matches my problem.
Using Unix cURL, I need to POST a key/val pair to a server. The key will be “MACs”, and the contents of a file of newline separated MAC addresses will be the VALUE for this POST.
I’ve tried:
curl -d @filename http://targetaddress.com, but when the target receives the incoming POST, the POST var is empty. (PHP is receiving).
I’ve seen other forms of curl mentioned on this site, using --url-encode which says it is not a valid option for curl on my system…
How do you POST the contents of a file as a value to a specific key in a POST using UNIX cURL?
According to curl man page -d is the same as –data-ascii. To post the data as binary use –data-binary and to post with url encoding use –data-urlencode. So as your file is not URL encoded if you want to send it URL encoded use:
If you file contains something like:
this will result in a POST request received something like:
If you want to add a name you can use multipart form encoding something like:
or