Friday, April 6, 2018

How to encode multiple parameter value on curl command?

Prerequisite

- CURL version 7.53.1 has been installed
- An web service is ready, for example, "https://www.api.com/query?"
- Multiple parameters are required to pass to the API, for example param1=value1&param2=value2 

Create a New REST API
  • Use the curl command to call the web service "curl https://www.api.com/query?param1=value1&param2=value2"
  • You may encounter the error message as shown below:-
'param1' is not recognized as an internal or external command,
operable program or batch file.
'param2' is not recognized as an internal or external command,
operable program or batch file.
  • To resolve this problem, url encoding is required.
  • Use the curl command to call the web service, error message as shown above is eliminated.
curl -G -v "https://www.api.com/query" --data-urlencode "param1=value1" --data-urlencode "param2=value2"