Difference between revisions of "The Web from the Command Line"
(Start writing out curl page.) |
(More curl content.) |
||
Line 8: | Line 8: | ||
curl <nowiki>http://www.lmu.edu</nowiki> > lmu.html | curl <nowiki>http://www.lmu.edu</nowiki> > lmu.html | ||
That’s it, really. Using '''curl''', you can get the content of a web page purely at the data level. No images are loaded, no layout is done, no visuals are rendered. This command is like the very first step that a web browser takes when visiting a website, except that it goes no further than that. | That’s it, really. Using '''curl''', you can get the content of a web page purely at the data level. No images are loaded, no layout is done, no visuals are rendered. This command is like the very first step that a web browser takes when visiting a website, except that it goes no further than that. | ||
+ | |||
+ | == Why curl? == | ||
+ | |||
+ | One look at this might beg the question of why the command exists at all, especially when we have web browsers that work perfectly fine for daily use. ''Daily use'' is the operative term here—of course '''curl''' is not meant to be a web browser replacement. Instead, as a command line program that performs a simple request/response cycle, '''curl''' can be used for scripting, automation, and other types of processing that go beyond the visual consumption of a website’s content. | ||
+ | |||
+ | == curl Mimics Requests in the Network Developer Tools Tab == | ||
+ | |||
+ | One such use of '''curl''' is to trigger requests that you can’t perform just by typing a URL into a web browser. The location bar in web browsers only perform what are called '''GET''' requests—requests that are meant to retrieve content from a server. Some requests, however, have a different ''method'', such as '''POST''' or '''PUT'''—these are meant to ''submit'' data to a server. On web browsers, you do this implicitly by filling out forms and clicking on some ''Submit'' button. If you don’t want to go through a browser or would like to do this automatically, you can use '''curl''': | ||
+ | {{ Under Construction }} |
Revision as of 02:06, 11 September 2017
Due to the “need-to-know” approach that we take in this course, our study of the command line necessarily takes a leap to a fairly powerful and advanced command. This command beings the web to the command line, and learning it helps one understand what is truly happening behind the scenes when we visit websites with our web browsers. That command is curl. Strictly speaking, it is spelled cURL because its name is intended to mean “see URL.” “See” and “c”—get it?
Basic Usage
Put simply, curl performs single web requests and displays the response provided by the contacted web server without further processing (nor layout). In its simplest form, one can just give it a URL:
curl http://www.lmu.edu
For most URLs, invoking this command will produce a flood of text—a perfect use case for more/less, or for output redirection in case you want to save the file to your computer:
curl http://www.lmu.edu > lmu.html
That’s it, really. Using curl, you can get the content of a web page purely at the data level. No images are loaded, no layout is done, no visuals are rendered. This command is like the very first step that a web browser takes when visiting a website, except that it goes no further than that.
Why curl?
One look at this might beg the question of why the command exists at all, especially when we have web browsers that work perfectly fine for daily use. Daily use is the operative term here—of course curl is not meant to be a web browser replacement. Instead, as a command line program that performs a simple request/response cycle, curl can be used for scripting, automation, and other types of processing that go beyond the visual consumption of a website’s content.
curl Mimics Requests in the Network Developer Tools Tab
One such use of curl is to trigger requests that you can’t perform just by typing a URL into a web browser. The location bar in web browsers only perform what are called GET requests—requests that are meant to retrieve content from a server. Some requests, however, have a different method, such as POST or PUT—these are meant to submit data to a server. On web browsers, you do this implicitly by filling out forms and clicking on some Submit button. If you don’t want to go through a browser or would like to do this automatically, you can use curl: