Curl command line encoding of query parameters for an HTTP PUT

[Note: I originally posted this problem/solution to Stackoverflow.com]

Problem:

I have multiple query parameters that I want to send in an HTTP PUT operation using curl. How do I encode the query parameters? Example:

If ‘value 1’ contains spaces or other characters that are interpreted by the shell, the command will not parse correctly.

Solution:

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:

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.

This entry was posted in Unix and tagged , , , , . Bookmark the permalink.

Leave a Reply