Trigger GET request from command prompt using Wget in windows

Divine
3 min readNov 27, 2017

Wget is a tool which could used for triggering GET request via command prompt .

There are many usecases in which Wget could be useful.

But in this article i would be discussing about an usecase in which Wget was most useful for me.

Wget could be useful in below use cases :

  1. if you want to test any GET requests
  2. if you want to trigger GET requests at specific intervals.

How to trigger GET requests at specific intervals?

a. You could store the Wget command with required URL in a .bat file.

b. Open windows scheduler.

c. Create a task and provide the .bat path as input parameter to trigger at the specific time/day.

How to use Wget?

Download wget from this url. There are other repositories from which you could download this package but the url of the package i have posted here works without any issue (kindly let me know if it is broken when you visit the page)

Extract the downloaded zip file. Go into extracted folder.

Copy the path.

Open command prompt and make sure its pointing to this path.

Type below command to test if Wget is working without errors

wget -h

If you are planning to use Wget to trigger any webservice at specific intervals using windows scheduler, make sure that you have configured Wget as environment variable.

Command to trigger GET requests

Command 1

wget http://localhost:8080/index

output of the command wget http://localhost:8080/index

What happened here?

You can observe following details in the output screenprint

  1. Connection successful to the web server. response 200
  2. Length of the response from the webserver
  3. At the last line you could see the text index.3

Now, what is index.3?

Wget logs the http response in a file and saves the file in the current directory from which you executed the command.

By default, the name of the log file will be extracted from the lastpart of the URL you triggered in the Wget command.

In ourcase the last part is index. So the log file with name index will get saved into your local directory.

If you trigger the same URL multiple times, an integer value will be appended to the log file as index.1 , index.2 . in my case i triggered the URL 3 times so the log file with name index.3 was generated.

It is possible to change the default name of the log file to an userdefined name. We will discuss that below.

Command 2

wget http://localhost:8080/index -O out.txt

output of the command wget http://localhost:8080/index -O out.txt

The Http response will be saved in the userdefined output file out.txt

Command 3

Passing request parameters using wget

wget http://localhost:8080/get?id=0 -O output.txt

output of the command wget http://localhost:8080/get?id=0 -O output.txt

Command 4

Passing path parameters using wget

wget http://localhost:8080/get/divine -O out.txt

output of the command wget http://localhost:8080/get/divine -O out.txt

i hope this information is useful to you.

Kindly let me know if you have any queries.

--

--