How can I test an HTTP POST query from the Linux command line?

by aglae_feil , in category: General Help , 5 months ago

How can I test an HTTP POST query from the Linux command line?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by anissa , 4 months ago

@aglae_feil 

You can test an HTTP POST query from the Linux command line using tools like curl or wget. Here's how you can do it with curl:

  1. Open a terminal on your Linux machine.
  2. Enter the following command: curl -X POST -d "param1=value1¶m2=value2" http://example.com/api/endpoint Replace param1=value1¶m2=value2 with the data you want to send as the body of the POST request. You can add more key-value pairs by separating them with an ampersand (&). Modify http://example.com/api/endpoint to the actual URL where you want to send the request.
  3. Press Enter. curl will send the POST request to the specified URL with the provided data. The server's response will be displayed in the terminal.


Alternatively, you can also use wget to test an HTTP POST query:

  1. Open a terminal on your Linux machine.
  2. Enter the following command: wget --post-data="param1=value1¶m2=value2" http://example.com/api/endpoint Like with curl, replace param1=value1¶m2=value2 with the data you want to send as the body of the POST request. Modify http://example.com/api/endpoint to the actual URL where you want to send the request.
  3. Press Enter. wget will send the POST request to the specified URL with the provided data. The server's response will be displayed in the terminal.


Choose the tool (curl or wget) that is available on your Linux system or suits your needs better.