Unix cURL POST for a specific variable using contents from a file

I searched for this answer, but did not find anything that works or is fully consistent with my problem.

Using Unix cURL, I need to send the / val key pair to the server. The key will be "MAC", and the contents of the MAC address file, separated by a new line, will be VALUE for this POST.

I tried:

curl -d @filename http://targetaddress.com , but when the target receives an incoming POST, POST var is empty. (Gets PHP).

I saw other curl forms mentioned on this site using --url-encode , which says this is not a valid curl option of my system ...

How do you send the contents of a file as a value for a specific key in POST using UNIX cURL?

+6
source share
1 answer

According to the curl page man -d is the same as -data-ascii. To publish data in binary, use -data-binary and to publish using url encoding, use -data-urlencode. Since your file is not URL encoded, if you want to send its URL encoding, use:

 curl --data-urlencode @file http://example.com 

If the file contains something like:

 00:0f:1f:64:7d:ff 00:0f:1f:64:7d:ff 00:0f:1f:64:7d:ff 

this will cause the POST request to get something like:

 POST / HTTP/1.1 User-Agent: curl/7.19.5 (i486-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15 Host: example.com Accept: */* Content-Length: 90 Content-Type: application/x-www-form-urlencoded 00%3A0f%3A1f%3A64%3A7d%3Aff%0A00%3A0f%3A1f%3A64%3A7d%3Aff%0A00%3A0f%3A1f%3A64%3A7d%3Aff%0A 

If you want to add a name, you can use multi-page form encoding, for example:

 curl -F MACS=@file http://example.com 

or

 curl -F MACS=<file http://example.com 
+4
source

Source: https://habr.com/ru/post/897706/


All Articles