10 Examples Of Curlicue Ascendance Inwards Unix As Well As Linux
The curl is ane of the essential commands to shipping HTTP requests from UNIX in addition to Linux operating System. twine ascendence is purpose of the cURL bundle in addition to it's non merely useful to shipping HTTP request but also allows you lot to transfer file using FTP in addition to shipping send using SMTP. The cURL utility supports many protocols including DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAP, LDAPS, LDAP, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTP, Telnet, in addition to TFTP. It also supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP cast based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate in addition to Kerberos), file transfer resume, proxy tunneling in addition to more. It's peculiarly useful if you lot are working amongst web services.
You tin utilization the curl ascendence to telephone band spider web services correct from UNIX ascendence prompt, have a response, depository fiscal establishment lucifer whether your server is salubrious or not. You tin write testing in addition to monitoring scripts using curl command. It's similar to wget command, which is also used for HTTP requests but it's much to a greater extent than powerful in addition to supports many protocols.
The twine ascendence is past times default available inwards many UNIX installation but if it's non you lot tin ever download the latest version from http://curl.haxx.se/download.html, the latest version of the cURL bundle is twine 7.43.0, released on 17th June 2015. cURL has unlike packages available for unlike UNIX season e.g. Linux, Debian, Fedora, ArchLinux, AIX, FreeBSD, Suse, Redhat, Ubuntu in addition to fifty-fifty for Mac OS X in addition to Apple iOS.
1) How to shipping HTTP asking from UNIX
You tin utilization curl or wget to shipping HTTP asking from UNIX, equally shown below:
By default, twine uses GET method to shipping HTTP request. You tin also utilization enquiry parameters piece connecting to spider web services using HTTP equally shown below:
Don't forget to include URL within unmarried quotes if you lot include to a greater extent than than ane enquiry parameters. Why? because multiple enquiry parameters are separated using & which has special important inwards the shell, to run the ascendence inwards the background, past times including it within unmarried quotes nosotros utilization it literally, equally shown below:
2) How to render timeout for HTTP asking inwards UNIX
Another interesting instance of twine ascendence is past times using -m option. You tin utilization curl -m pick to render a timeout for HTTP request. If server volition non render whatever answer within specified fourth dimension menstruation hence twine volition exit, equally shown below
volition hold back for 3 seconds before timing out. BTW, -m is used for a span of things inwards twine e.g. for the maximum publish of redirects in addition to maximum file size to download.
Alternatively, you lot tin utilization to a greater extent than verbose --max-time, --max-redirs in addition to --max-filesize options. Worth noting is maximum fourth dimension allowed for transfer is inwards seconds, which agency -m 5 agency v seconds. You tin utilization this pick to depository fiscal establishment lucifer whether your website or spider web service is responsive or not.
3) How to shipping HTTP POST asking from Linux
You tin shipping whatever type of HTTP asking past times using twine -X ascendence inwards Linux. It allows you lot to specify HTTP methods other than GET, for example, next ascendence volition shipping HTTP POST asking from linux ascendence line:
Since GET is the default method, you lot don't withdraw to specify it but if you lot desire to shipping other HTTP methods e.g. PUT or POST, you lot tin utilization this option. Btw, what is the utilization of POST asking without sending whatever data? Let's encounter our side past times side example, which allows you lot to shipping information to the server using twine command.
4) How to shipping information using HTTP POST inwards UNIX
You tin also shipping POST asking using twine -d option. -d is cypher but for data, which is sent equally POST body. The information is expected to hold out URL-encoded.
This volition shipping enquiry parameters equally a POST request. You tin also utilization -d pick multiple times to specify unlike information pieces e.g.
This volition eventually hold out combined equally -d 'lat=35&lon=139'. The -d pick tin also hold out used to submit HTML cast information to the server. You tin encounter The Linux ascendence line: A consummate Introduction for to a greater extent than details on sending information using twine command.
5) How to shipping a file via HTTP POST inwards Linux
If your information is large, you lot tin buy the farm along them within a file in addition to say twine the file name. It volition transfer all that information using HTTP shipping asking to the server, hither is an instance of sending a file using curl:
The @ sign tells twine that whatever follows is a file name. BTW, the content of file must hold out URL encoded. You tin also use --data instead of -d if you lot prefer the most verbose option.
6) How to shipping username password for authentication using curl
You tin utilization twine -u pick to locomote past times username in addition to password for authentication. The -u pick is a shortcut of --user pick which specifies username in addition to password for server authentication. If you lot using twitter, hither is how you lot tin update your condition using twine ascendence correct from UNIX:
If you lot don't wishing your password to hold out saved inwards the vanquish history, you lot tin omit password purpose in addition to twine volition prompt for password when it tries to authenticate on the server. As I told earlier, -d instructs twine to utilization HTTP POST method to shipping a asking in addition to "status=.." volition hold out sent equally purpose of the asking body. You tin farther read Practical guide to Linux ascendence in addition to vanquish editors to larn to a greater extent than virtually it.
7) How to specify HTTP header using twine ascendence inwards Linux
You tin specify HTTP header past times using curl -H option. Since amongst spider web service you lot ofttimes bargain amongst either JSON or XML rather than HTML, it makes feel to specify content-type equally either "application/json" or "application/xml". You tin practise this using twine equally shown inwards the next example:
You tin also utilization headers piece sending information to server using HTTP shipping e.g.
One side tip, you lot tin carve upwards your UNIX command into multiple lines past times using \ (backslash). It makes your ascendence to a greater extent than readable, especially if it's getting long.
8) How to thought HTTP answer header inwards Linux
You tin utilization the curl -i ascendence to thought answer header inwards UNIX. Since API in addition to WebService provider is increasingly using HTTP header to render information virtually caching, content-type, authorisation etc, it's rattling useful to encounter HTTP header using twine equally shown below:
This volition render all answer headers from HTTP answer equally shown below:
That's all virtually how to utilization twine ascendence to shipping HTTP asking in addition to have a response. We bring seen several examples of twine ascendence ranging from sending uncomplicated HTTP asking to timeout, amongst enquiry parameters in addition to unlike types of HTTP asking e.g. POST, PUT, in addition to DELETE.
It's truly a must know tool if you lot are working amongst REST spider web services which render JSON or XML output. You tin bear witness your spider web services correct from UNIX box, tin construct scripts to bear witness in addition to monitor them equally well. As a Java developer, I utilization twine a lot when I locomote amongst spider web services based application.
Further Learning
Linux Command Line Basics
examples)
10 examples of grep ascendence inwards Linux (see)
10 examples of sed ascendence inwards UNIX (see)
10 examples of chmod ascendence inwards Linux (see)
10 examples of xargs ascendence inwards Linux (see)
10 Essential Networking commands inwards Linux (see)
10 examples of lsof ascendence inwards Linux (see)
10 Examples of tar ascendence inwards Linux (see)
Thanks for reading this tutorial, if you lot similar hence delight part amongst friends in addition to colleagues. If you lot bring whatever other interesting twine examples, which you lot utilization daily or detect useful, experience costless to part amongst us too.,
You tin utilization the curl ascendence to telephone band spider web services correct from UNIX ascendence prompt, have a response, depository fiscal establishment lucifer whether your server is salubrious or not. You tin write testing in addition to monitoring scripts using curl command. It's similar to wget command, which is also used for HTTP requests but it's much to a greater extent than powerful in addition to supports many protocols.
The twine ascendence is past times default available inwards many UNIX installation but if it's non you lot tin ever download the latest version from http://curl.haxx.se/download.html, the latest version of the cURL bundle is twine 7.43.0, released on 17th June 2015. cURL has unlike packages available for unlike UNIX season e.g. Linux, Debian, Fedora, ArchLinux, AIX, FreeBSD, Suse, Redhat, Ubuntu in addition to fifty-fifty for Mac OS X in addition to Apple iOS.
10 Example of twine ascendence inwards Linux
Here are roughly of the useful examples of twine ascendence inwards Linux. You tin utilization this ascendence to bear witness your REST API from the Linux ascendence line. You tin also depository fiscal establishment lucifer if your spider web application is upwards in addition to downward past times using twine ascendence inwards a script in addition to hence running it from crontab or a scheduling application similar Autosys.1) How to shipping HTTP asking from UNIX
You tin utilization curl or wget to shipping HTTP asking from UNIX, equally shown below:
$ twine http://google.com
By default, twine uses GET method to shipping HTTP request. You tin also utilization enquiry parameters piece connecting to spider web services using HTTP equally shown below:
$ twine http://api.openweathermap.org/data/2.5/weather?id=2172797
Don't forget to include URL within unmarried quotes if you lot include to a greater extent than than ane enquiry parameters. Why? because multiple enquiry parameters are separated using & which has special important inwards the shell, to run the ascendence inwards the background, past times including it within unmarried quotes nosotros utilization it literally, equally shown below:
$ twine 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139' 2) How to render timeout for HTTP asking inwards UNIX
Another interesting instance of twine ascendence is past times using -m option. You tin utilization curl -m pick to render a timeout for HTTP request. If server volition non render whatever answer within specified fourth dimension menstruation hence twine volition exit, equally shown below
$ twine -m 3 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'
volition hold back for 3 seconds before timing out. BTW, -m is used for a span of things inwards twine e.g. for the maximum publish of redirects in addition to maximum file size to download.
Alternatively, you lot tin utilization to a greater extent than verbose --max-time, --max-redirs in addition to --max-filesize options. Worth noting is maximum fourth dimension allowed for transfer is inwards seconds, which agency -m 5 agency v seconds. You tin utilization this pick to depository fiscal establishment lucifer whether your website or spider web service is responsive or not.
3) How to shipping HTTP POST asking from Linux
You tin shipping whatever type of HTTP asking past times using twine -X ascendence inwards Linux. It allows you lot to specify HTTP methods other than GET, for example, next ascendence volition shipping HTTP POST asking from linux ascendence line:
$ twine -X POST http://api.openweathermap.org
Since GET is the default method, you lot don't withdraw to specify it but if you lot desire to shipping other HTTP methods e.g. PUT or POST, you lot tin utilization this option. Btw, what is the utilization of POST asking without sending whatever data? Let's encounter our side past times side example, which allows you lot to shipping information to the server using twine command.
4) How to shipping information using HTTP POST inwards UNIX
You tin also shipping POST asking using twine -d option. -d is cypher but for data, which is sent equally POST body. The information is expected to hold out URL-encoded.
$ twine -d 'lat=35&lon=139' http://api.openweathermap.org/data/2.5/weather
This volition shipping enquiry parameters equally a POST request. You tin also utilization -d pick multiple times to specify unlike information pieces e.g.
$ twine -d lat=35 -d lon=139 http://api.openweathermap.org/data/2.5/weather
This volition eventually hold out combined equally -d 'lat=35&lon=139'. The -d pick tin also hold out used to submit HTML cast information to the server. You tin encounter The Linux ascendence line: A consummate Introduction for to a greater extent than details on sending information using twine command.
5) How to shipping a file via HTTP POST inwards Linux
If your information is large, you lot tin buy the farm along them within a file in addition to say twine the file name. It volition transfer all that information using HTTP shipping asking to the server, hither is an instance of sending a file using curl:
$ twine -d @requestData.txt http://api.openweathermap.org/data/2.5/weather
The @ sign tells twine that whatever follows is a file name. BTW, the content of file must hold out URL encoded. You tin also use --data instead of -d if you lot prefer the most verbose option.
6) How to shipping username password for authentication using curl
You tin utilization twine -u pick to locomote past times username in addition to password for authentication. The -u pick is a shortcut of --user pick which specifies username in addition to password for server authentication. If you lot using twitter, hither is how you lot tin update your condition using twine ascendence correct from UNIX:
$ twine -u username:password -d status='curl is great' http://twitter.com/statuses/update.xml
If you lot don't wishing your password to hold out saved inwards the vanquish history, you lot tin omit password purpose in addition to twine volition prompt for password when it tries to authenticate on the server. As I told earlier, -d instructs twine to utilization HTTP POST method to shipping a asking in addition to "status=.." volition hold out sent equally purpose of the asking body. You tin farther read Practical guide to Linux ascendence in addition to vanquish editors to larn to a greater extent than virtually it.
7) How to specify HTTP header using twine ascendence inwards Linux
You tin specify HTTP header past times using curl -H option. Since amongst spider web service you lot ofttimes bargain amongst either JSON or XML rather than HTML, it makes feel to specify content-type equally either "application/json" or "application/xml". You tin practise this using twine equally shown inwards the next example:
$ twine -H "Accept: application/json" 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'
You tin also utilization headers piece sending information to server using HTTP shipping e.g.
$ twine -X PUT \ -H 'Content-Type: application/json' \ -d '{"id":"101", "description":"baby soap"}' http://localhost:8080/item/add
One side tip, you lot tin carve upwards your UNIX command into multiple lines past times using \ (backslash). It makes your ascendence to a greater extent than readable, especially if it's getting long.
8) How to thought HTTP answer header inwards Linux
You tin utilization the curl -i ascendence to thought answer header inwards UNIX. Since API in addition to WebService provider is increasingly using HTTP header to render information virtually caching, content-type, authorisation etc, it's rattling useful to encounter HTTP header using twine equally shown below:
$ twine -i http://api.openweathermap.org/data/2.5/weather?zip=94040,us
This volition render all answer headers from HTTP answer equally shown below:
That's all virtually how to utilization twine ascendence to shipping HTTP asking in addition to have a response. We bring seen several examples of twine ascendence ranging from sending uncomplicated HTTP asking to timeout, amongst enquiry parameters in addition to unlike types of HTTP asking e.g. POST, PUT, in addition to DELETE.
It's truly a must know tool if you lot are working amongst REST spider web services which render JSON or XML output. You tin bear witness your spider web services correct from UNIX box, tin construct scripts to bear witness in addition to monitor them equally well. As a Java developer, I utilization twine a lot when I locomote amongst spider web services based application.
Further Learning
Linux Command Line Basics
examples)
10 examples of grep ascendence inwards Linux (see)
10 examples of sed ascendence inwards UNIX (see)
10 examples of chmod ascendence inwards Linux (see)
10 examples of xargs ascendence inwards Linux (see)
10 Essential Networking commands inwards Linux (see)
10 examples of lsof ascendence inwards Linux (see)
10 Examples of tar ascendence inwards Linux (see)
Thanks for reading this tutorial, if you lot similar hence delight part amongst friends in addition to colleagues. If you lot bring whatever other interesting twine examples, which you lot utilization daily or detect useful, experience costless to part amongst us too.,




0 Response to "10 Examples Of Curlicue Ascendance Inwards Unix As Well As Linux"
Post a Comment