In my coding process, i need to manually fire http request with both get or post method to test my web application, the easiest way to do this is to use curl command. this article will tell you how to do it.
1. Use curl In Linux.
- Run below command to verify curl tool has been installed in your Linux os. If you see the correct output like below, it means curl has been installed.
~$ curl --version curl 7.63.0 (x86_64-conda_cos6-linux-gnu) libcurl/7.63.0 OpenSSL/1.1.1a zlib/1.2.11 libssh2/1.8.0 Release-Date: 2018-12-12 Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy
- If you find curl is not installed, you can run below command to install it in ubuntu Linux, for other linux your can goto curl official website to download related package and install.
~$ sudo apt-get update ...... ~$ sudo apt-get install curl ...... ~$ curl --version
2. Use curl In Windows.
- Open a dos window, and run
curl --version
command to verify whether curl has been installed or not. If curl has been installed, you can see below output.C:\Users\>curl --version curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL Release-Date: [unreleased] Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
- If you want to install or upgrade your curl, you can download the newest curl window installer and extract it.
- Open a dos window and cd into the new curl extract folder like below, and run curl executable file, now you can see the curl command is the newst version.
C:\Users\zhaosong>cd C:\Users\zhaosong\Downloads\curl-7.64.1-win64-mingw\bin C:\Users\zhaosong\Downloads\curl-7.64.1-win64-mingw\bin>dir Volume in drive C has no label. Volume Serial Number is 7689-56A2 Directory of C:\Users\zhaosong\Downloads\curl-7.64.1-win64-mingw\bin 03/04/2019 13:37 <DIR> . 03/04/2019 13:37 <DIR> .. 23/01/2019 04:12 219,596 curl-ca-bundle.crt 27/03/2019 06:57 4,108,920 curl.exe 27/03/2019 06:57 1,023,608 libcurl-x64.dll 3 File(s) 5,352,124 bytes 2 Dir(s) 543,658,016,768 bytes free C:\Users\zhaosong\Downloads\curl-7.64.1-win64-mingw\bin>curl.exe --version curl 7.64.1 (x86_64-pc-win32) libcurl/7.64.1 OpenSSL/1.1.1b (Schannel) zlib/1.2.11 brotli/1.0.7 WinIDN libssh2/1.8.2 nghttp2/1.37.0 Release-Date: 2019-03-27 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP brotli libz
3. Fire Http Get Post Method Use Curl.
3.1 Fire Http Get Request.
curl -i -X GET http://www.yahoo.com
3.2 Fire Http Post Request.
curl -i -X POST -H 'Content-Type: application/json' -d '{"name": "New item", "year": "2009"}' http://www.yahoo.com
3.3 Get curl Help.
To learn more curl usage options, run below command to get curl help.
curl --help