How To Post Http Asking From Unix Or Linux? Purpose Twine Or Wget Command
You tin sack purpose either curl or wget ascendance to ship HTTP asking from UNIX or Linux operating system. Both commands allow y'all to ship GET together with POST request, which agency y'all tin sack likewise telephone phone REST spider web services. I bring a Java spider web application, which runs on Linux together with exposes WebServices. I was writing a UNIX script to download In or thus information from that spider web service when I striking past times the question, how produce I brand an HTTP telephone phone from UNIX? What is the UNIX ascendance should I use? If y'all are likewise facing the same question, thus y'all bring come upwards to correct place. Basically, y'all tin sack purpose 2 UNIX commands to brand the HTTP request, wget, together with curl. You tin sack purpose ringlet together with wget to ship both GET together with POST HTTP request. My purpose instance was rather simple, I but necessitate to brand a GET telephone phone to spider web service to download the data, but these 2 commands are real powerful together with furnish many dissimilar options to interact amongst the spider web using HTTP correct from the shell.
Between wget together with curl (also known equally cURL), ringlet (I telephone phone it "karl") is my favorite. Why? I think because I bring used it to a greater extent than oft than wget :-). You tin sack brand your choices if y'all bring proficient cognition of Linux ascendance business together with that's why I advise every Java developer to read The Linux Command Line: H5N1 Complete Reference, the best way to dice efficient inwards Linux. Now let's encounter how to ship HTTP asking from UNIX using the ringlet command.
You tin sack likewise specify timeout using -m choice equally shown below:
This asking volition timeout inwards 2 seconds if it doesn't have whatever response.
You tin sack likewise purpose wget to ship HTTP asking together with download the data. Only deviation betwixt curl together with wget is that curl volition impress output inwards console together with wget volition shop it inwards the file e.g.
volition download the content of index.html together with shop into a file amongst the same name.
Here is how y'all tin sack purpose ringlet to download wget ascendance inwards UNIX:
if y'all desire to ship a information from file to spider web service, y'all tin sack likewise purpose the next command:
Similarly, if y'all desire to upload a file y'all tin sack produce thus past times executing the next command:
That's all close how to ship HTTP asking from UNIX together with Linux. It's simple, but retrieve ringlet together with wget command. y'all tin sack explore their choice past times using human being wget together with human being curl. Also, retrieve the deviation betwixt ringlet together with wget, old prints the output inwards the console piece afterward shop the response inwards the same file equally requested. I personally similar ringlet because it's easier to purpose but if y'all similar wget stick amongst it.
Further Learning
Linux Command Line Basics
examples)10 examples of grep ascendance inwards UNIX (examples) 10 examples of appointment ascendance inwards Linux (examples) How to larn IP address from hostname together with vice-versa inwards Linux (command) 10 examples of xargs ascendance inwards Linux (examples) 10 examples of tar ascendance inwards UNIX (examples) 10 examples of Vim inwards UNIX (examples) How to create, update together with delete soft link inwards UNIX (command) How to delete empty files together with directory inwards UNIX (solution) How to brand directory tree inwards i command? (example) How to how long declaration of a procedure inwards Solaris (command) UNIX ascendance to honor out how long a procedure is running? (answer) UNIX ascendance to honor the size of file together with directory? (command) 5 examples of variety ascendance inwards Linux (examples) 5 examples of kill ascendance inwards Linux (examples) 10 examples of chmod ascendance inwards UNIX (examples) 10 tips to operate fast inwards UNIX? (tips)
Thanks for reading this article thus far. If y'all similar this article thus delight percentage amongst your friends together with colleagues. If y'all bring whatever questions or feedback thus delight drib a note.
Between wget together with curl (also known equally cURL), ringlet (I telephone phone it "karl") is my favorite. Why? I think because I bring used it to a greater extent than oft than wget :-). You tin sack brand your choices if y'all bring proficient cognition of Linux ascendance business together with that's why I advise every Java developer to read The Linux Command Line: H5N1 Complete Reference, the best way to dice efficient inwards Linux. Now let's encounter how to ship HTTP asking from UNIX using the ringlet command.
UNIX ascendance to ship HTTP GET request
Here is i illustration of calling spider web service from Linux compaction past times sending HTTP GET request using cURL command:$ ringlet http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=bd82977b86bf27fb59a04b61b657fb6f {"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"base":"stations","main":{"temp":282,"pressure":1022,"humidity":87,"temp_min":277.15,"temp_max":285.15},"visibility":10000,"wind":{"speed":1.5},"clouds":{"all":90},"dt":1445577409,"sys":{"type":1,"id":5093,"message":0.0201,"country":"GB","sunrise":1445582275,"sunset":1445619056},"id":2643743,"name":"London","cod":200}
You tin sack likewise specify timeout using -m choice equally shown below:
$ ringlet -m 2 http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=bd82977b86bf27fb59a04b61b657fb6f
This asking volition timeout inwards 2 seconds if it doesn't have whatever response.
You tin sack likewise purpose wget to ship HTTP asking together with download the data. Only deviation betwixt curl together with wget is that curl volition impress output inwards console together with wget volition shop it inwards the file e.g.
$ wget http://localhost:8080/index.html
volition download the content of index.html together with shop into a file amongst the same name.
Here is how y'all tin sack purpose ringlet to download wget ascendance inwards UNIX:
UNIX ascendance to ship HTTP POST request
You tin sack likewise purpose ringlet to ship HTTP postal service request. All y'all necessitate to produce is purpose the --data choice to specify the information y'all desire to POST to spider web service e.g.$ curl --data "param1=value1¶m2=value2" http://locahost:8080/weather
if y'all desire to ship a information from file to spider web service, y'all tin sack likewise purpose the next command:
$ ringlet -X POST -d @filename http://locahost:8080/weather
Similarly, if y'all desire to upload a file y'all tin sack produce thus past times executing the next command:
$ ringlet --form "fileupload=@filename.txt" http://locahost:8080/weather
That's all close how to ship HTTP asking from UNIX together with Linux. It's simple, but retrieve ringlet together with wget command. y'all tin sack explore their choice past times using human being wget together with human being curl. Also, retrieve the deviation betwixt ringlet together with wget, old prints the output inwards the console piece afterward shop the response inwards the same file equally requested. I personally similar ringlet because it's easier to purpose but if y'all similar wget stick amongst it.
Further Learning
Linux Command Line Basics
examples)
Thanks for reading this article thus far. If y'all similar this article thus delight percentage amongst your friends together with colleagues. If y'all bring whatever questions or feedback thus delight drib a note.


Komentar
Posting Komentar