10 Examples Of Wind Ascendancy Inwards Unix As Well As Linux

The curl is ane of the essential commands to ship HTTP requests from UNIX in addition to Linux operating System. curlicue ascendency is business office of the cURL packet in addition to it's non but useful to ship HTTP request but also allows you lot to transfer file using FTP in addition to ship postal service 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 especially useful if you lot are working amongst web services.

You tin ship away purpose the curl ascendency to telephone telephone spider web services correct from UNIX ascendency prompt, have a response, banking concern friction match whether your server is good for you lot or not. You tin ship away 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 curlicue ascendency is yesteryear default available inward many UNIX installation but if it's non you lot tin ship away ever download the latest version from http://curl.haxx.se/download.html, the latest version of the cURL packet is curlicue 7.43.0, released on 17th June 2015. cURL has dissimilar packages available for dissimilar UNIX flavour 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 curlicue ascendency inward Linux

Here are to a greater extent than or less of the useful examples of curlicue ascendency inward Linux. You tin ship away purpose this ascendency to try your REST API from the Linux ascendency line. You tin ship away also banking concern friction match if your spider web application is upwardly in addition to downwardly yesteryear using curlicue ascendency inward a script in addition to and thence running it from crontab or a scheduling application similar Autosys.

1) How to ship HTTP asking from UNIX
You tin ship away purpose curl or wget to ship HTTP asking from UNIX, every bit shown below:

$ curlicue http://google.com

By default, curlicue uses GET method to ship HTTP request. You tin ship away also purpose inquiry parameters piece connecting to spider web services using HTTP every bit shown below:

$ curlicue 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 inquiry parameters. Why? because multiple inquiry parameters are separated using & which has special pregnant inward the shell, to run the ascendency inward the background, yesteryear including it within unmarried quotes nosotros purpose it literally, every bit shown below:

$ curlicue 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'



2) How to render timeout for HTTP asking inward UNIX
Another interesting lawsuit of curlicue ascendency is yesteryear using -m option. You tin ship away purpose curl -m pick to render a timeout for HTTP request. If server volition non render whatsoever answer within specified fourth dimension menses in addition to thence curlicue volition exit, every bit shown below

$ curlicue -m 3 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'

volition hold off for 3 seconds before timing out. BTW, -m is used for a dyad of things inward curlicue e.g. for the maximum let on of redirects in addition to maximum file size to download.

Alternatively, you lot tin ship away purpose 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 inward seconds, which way -m 5 way five seconds. You tin ship away purpose this pick to banking concern friction match whether your website or spider web service is responsive or not.

 is ane of the essential commands to ship HTTP requests from UNIX in addition to Linux operating Syst 10 Examples of curlicue Command inward UNIX in addition to Linux


3) How to ship HTTP POST asking from Linux
You tin ship away ship whatsoever type of HTTP asking yesteryear using curlicue -X ascendency inward Linux. It allows you lot to specify HTTP methods other than GET, for example, next ascendency volition ship HTTP POST asking from linux ascendency line:

$ curlicue -X POST http://api.openweathermap.org

Since GET is the default method, you lot don't involve to specify it but if you lot desire to ship other HTTP methods e.g. PUT or POST, you lot tin ship away purpose this option. Btw, what is the purpose of POST asking without sending whatsoever data? Let's run into our side yesteryear side example, which allows you lot to ship information to the server using curlicue command.


4) How to ship information using HTTP POST inward UNIX
You tin ship away also ship POST asking using curlicue -d option. -d is aught but for data, which is sent every bit POST body. The information is expected to live on URL-encoded.

$ curlicue -d 'lat=35&lon=139' http://api.openweathermap.org/data/2.5/weather

This volition ship inquiry parameters every bit a POST request. You tin ship away also purpose -d pick multiple times to specify dissimilar information pieces e.g.

$ curlicue -d lat=35 -d lon=139 http://api.openweathermap.org/data/2.5/weather

This volition eventually live on combined every bit -d 'lat=35&lon=139'. The -d pick tin ship away also live on used to submit HTML cast information to the server. You tin ship away run into The Linux ascendency line:  A consummate Introduction for to a greater extent than details on sending information using curlicue command.

 is ane of the essential commands to ship HTTP requests from UNIX in addition to Linux operating Syst 10 Examples of curlicue Command inward UNIX in addition to Linux



5) How to ship a file via HTTP POST inward Linux
If your information is large, you lot tin ship away conk along them within a file in addition to say curlicue the file name. It volition transfer all that information using HTTP mail asking to the server, hither is an lawsuit of sending a file using curl:

$ curlicue -d @requestData.txt http://api.openweathermap.org/data/2.5/weather

The @ sign tells curlicue that whatever follows is a file name. BTW, the content of file must live on URL encoded. You tin ship away also use --data instead of -d if you lot prefer the most verbose option.


6) How to ship username password for authentication using curl
You tin ship away purpose curlicue -u pick to top 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 ship away update your condition using curlicue ascendency correct from UNIX:

$ curlicue -u username:password -d status='curl is great'  http://twitter.com/statuses/update.xml


If you lot don't want your password to live on saved inward the vanquish history, you lot tin ship away omit password business office in addition to curlicue volition prompt for password when it tries to authenticate on the server. As I told earlier, -d instructs curlicue to purpose HTTP POST method to ship a asking in addition to "status=.." volition live on sent every bit business office of the asking body. You tin ship away farther read Practical guide to Linux ascendency in addition to vanquish editors to larn to a greater extent than well-nigh it.

 is ane of the essential commands to ship HTTP requests from UNIX in addition to Linux operating Syst 10 Examples of curlicue Command inward UNIX in addition to Linux



7) How to specify HTTP header using curlicue ascendency inward Linux
You tin ship away specify HTTP header yesteryear 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 every bit either "application/json" or "application/xml". You tin ship away exercise this using curlicue every bit shown inward the next example:

$ curlicue -H "Accept: application/json"  'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'

You tin ship away also purpose headers piece sending information to server using HTTP mail e.g.

$ curlicue -X PUT \ -H 'Content-Type: application/json' \ -d '{"id":"101", "description":"baby soap"}' http://localhost:8080/item/add

One side tip, you lot tin ship away split upwardly your UNIX command into multiple lines yesteryear using \ (backslash). It makes your ascendency to a greater extent than readable, especially if it's getting long.


8) How to sentiment HTTP answer header inward Linux
You tin ship away purpose the curl -i ascendency to sentiment answer header inward UNIX. Since API in addition to WebService provider is increasingly using HTTP header to render information well-nigh caching, content-type, authorisation etc, it's real useful to run into HTTP header using curlicue every bit shown below:

$ curlicue -i http://api.openweathermap.org/data/2.5/weather?zip=94040,us

This volition render all answer headers from HTTP answer every bit shown below:

 is ane of the essential commands to ship HTTP requests from UNIX in addition to Linux operating Syst 10 Examples of curlicue Command inward UNIX in addition to Linux


That's all well-nigh how to purpose curlicue ascendency to ship HTTP asking in addition to have a response. We convey seen several examples of curlicue ascendency ranging from sending unproblematic HTTP asking to timeout, amongst inquiry parameters in addition to dissimilar types of HTTP asking e.g. POST, PUT, in addition to DELETE.

It's genuinely a must know tool if you lot are working amongst REST spider web services which render JSON or XML output. You tin ship away try your spider web services correct from UNIX box, tin ship away construct scripts to try in addition to monitor them every bit well. As a Java developer, I purpose curlicue a lot when I function amongst spider web services based application.

Further Learning
Linux Command Line Basics
examples)
10 examples of grep ascendency inward Linux (see)
10 examples of sed ascendency inward UNIX (see)
10 examples of chmod ascendency inward Linux (see)
10 examples of xargs ascendency inward Linux (see)
10 Essential Networking commands inward Linux (see)
10 examples of lsof ascendency inward Linux (see)
10 Examples of tar ascendency inward Linux (see)

Thanks for reading this tutorial, if you lot similar in addition to thence delight portion amongst friends in addition to colleagues. If you lot convey whatsoever other interesting curlicue examples, which you lot purpose daily or honour useful, experience costless to portion amongst us too., 

Sumber https://javarevisited.blogspot.com/

0 Response to "10 Examples Of Wind Ascendancy Inwards Unix As Well As Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel