How do I send GET and POST requests with parameter gimmeflag and value please to the URL using curl on the command line?


3 Answers 3


Seems like you following a tutorial or book and this is a cheeky way to test if you got the basics down.

Calling via curl or browser yields the following output:

Please send me request method GET and POST with params "gimmeflag" and value "please"

Let's break it down into two parts since you want to know how its done with curl (see man 1 curl or the curl manual).

Using GET to send your request:

This one is pretty easy if you know how a query-string looks like.

On the World Wide Web, a query string is the part of a uniform resource locator (URL) containing data that does not fit conveniently into a hierarchical path structure. The query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML form.

A web server can handle a Hypertext Transfer Protocol request either by reading a file from its file system based on the URL path or by handling the request using logic that is specific to the type of resource. In cases where special logic is invoked, the query string will be available to that logic for use in its processing, along with the path component of the URL.(source)

You want to send a parameter gimmeflag and a value please. So the line you want to request with curl is :

curl -X GET

The result you get back from the server:


Using POST to send your request:

Given the GET line the POST is pretty easy too just replace GET by POST:

curl -X POST

The result you get back from the server:


To conclude this:

# Thanks to @pa4080 for this line
printf '%s%s\n' \
"$(curl -X GET 2>/dev/null)" \
"$(curl -X POST 2>/dev/null)"



I answer here because I don't have enough rep to comment. There are two answers and the most voted answer does not know the workings of the HTTP protocol.

POST data travels in the body of the HTTP payload, not in the URL. A query string in the URL is just a trick to send data trough GET which is not an action made for posting data (GET and POST are self explanatory).

The correct way to use curl with POST would be:

curl -X POST -d "gimmeflag=please"

If one tests a script implemented in a language where GET and POST variables are separated, curl -X POST will store variables where GET variables are found.


This answer shows a way how could be achieved the results of @Videonauth's answer, but with wget:

$ wget -qO- 
Please send me request method GET and POST with params "gimmeflag" and value "please"
$ wget -qO- # GET is the default request
$ wget -qO- --post-data '' # Simple POST req.
$ printf '\n%s%s\n' \
"$(wget -qO- 2>/dev/null)" \
"$(wget -qO- --post-data '' 2>/dev/null)"


From man wget:

-O file; --output-document=file - The documents will not be written to the appropriate 
     files, but all will be concatenated together and written to file. If '-' is used 
     as file, documents will be printed to standard output, disabling link conversion...

-q; --quiet - Turn off Wget's output.

--post-data=string; --post-file=file - Use POST as the method for all HTTP requests 
     and send the specified data in the request body. --post-data sends string as data, 
     whereas --post-file sends the contents of file. Other than that, they work in 
     exactly the same way. In particular, they both expect content of the form 
     "key1=value1&key2=value2", with percent-encoding for special characters... 
     Only one of --post-data and --post-file should be specified... This example shows 
     how to log in to a server using POST and then proceed to download the desired pages, 
     presumably only accessible to authorized users:

         # Log in to the server.  This can be done only once.
         wget --save-cookies cookies.txt --post-data 'user=foo&password=bar' \
  • 2
    Now we only need to know which tutorial or book the OP was following and we could even make the question better.
    – Videonauth
    Nov 24, 2017 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.