Curl command line encoding of query parameters for an HTTP PUT
The solution is to use the -G
switch in combination with the --data-urlencode
switch. Using the original example, the command would look like the following:
$ curl -X PUT -G 'http://example.com/resource/1' --data-urlencode 'param1=value 1' --data-urlencode param2=value2
The -G
switch causes the parameters encoded with the --data-urlencode
switches to be appended to the end of the http URL with a ?
separator.
In the example, the value of param1
, would be encoded as value%201
, where %20 is the encoded value for a space character.
PUT requests are actually working like POST requests.
You should use$ curl -X PUT --data "param1=value1¶m2=value2" http://whatever
Data should be x-www-form-urlencode
d.
EDIT: Though it is totally contrary to the standard, I've seen instances where the request body must both had to be appended as a query string and passed as form-data.
LinkedIn API is the most notable.