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

by aglae_feil , in category: General Help , a year ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by anissa , a year 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.

Member

by modesta , 7 months ago

@aglae_feil 

Here is an example of using curl to test an HTTP POST request from the Linux command line

1
curl -X POST http://example.com/api/endpoint -d "param1=value1&param2=value2"


In this command:

  • -X POST specifies that this is a POST request.
  • http://example.com/api/endpoint is the URL where the POST request will be sent.
  • -d "param1=value1¶m2=value2" specifies the data to be sent in the body of the POST request. You can add more key-value pairs by separating them with an ampersand (&).


Upon running this command, curl will send a POST request to the specified URL with the provided data. The server's response will be displayed in the terminal.


Make sure to replace http://example.com/api/endpoint with the actual URL you want to send the request to, and adjust the data parameters accordingly based on your specific needs.