Curl: GET and POST Request

GET Request

To call a GET request to localhost:8080/path

curl localhost:8080/path

GET Request with Parameter Query

To call a GET request to localhost:8080/path?param1&value1&param2=value2

curl -G localhost:8080/path -d param1=value1 -d param2=value2
curl -G localhost:8080/path -d param1="value1" -d param2="value2"
curl -G localhost:8080/path -d "param1=value1" -d "param2=value2"
curl -G localhost:8080/path -d "param1=value1&param2=value2"
curl "localhost:8080/path?param1=value1&param2=value2"

Use wget:

wget localhost:8080/path
wget localhost:8080/path?param1=value1
# If there are more than one query parameter, enclose with double quotes
wget "localhost:8080/path?param1=value1&param2=value2"

POST Request (application/x-www-form-urlencoded)

To call a POST request to localhost:8080/path

curl localhost:8080/path -d name1=value1 -d name2=value2
curl localhost:8080/path -d name1="value1" -d name2="value2"
curl localhost:8080/path -d "name1=value1" -d "name2=value2"
curl localhost:8080/path -d "name1=value1&name2=value2"

POST Request with Query Parameters

curl "localhost:8080/path?param1=pvalue1&param2=pvalue2"

POST Request (multipart/form-data)

To call a POST request to localhost:8080/path

curl localhost:8080/path -F name1=value1 -F name2=value2
curl localhost:8080/path -F name1="value1" -F name2="value2"
curl localhost:8080/path -F "name1=value1" -F "name2=value2"

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *