![]() $ http POST name='Dan Nanni' comment='Hi there'Ĭontent-Type: application/json charset=utf-8 So if you send data fields without specifying any content-type, they will automatically be serialized as a JSON object. In fact, the default content-type used by HTTPie is JSON. HTTPie comes with built-in JSON support, which is nice considering its growing popularity as a data exchange format. The HTTP POST request will look like: POST / HTTP/1.1Ĭontent-Type: application/x-www-form-urlencoded charset=utf-8 The -f option lets http command serialize data fields, and set Content-Type to " application/x-www-form-urlencoded charset=utf-8". Submitting a form with http command is as easy as: $ http -f POST name='Dan Nanni' comment='Hi there' For example, to sent an HTTP PUT request: $ http PUT name='Dan Nanni' Example 4: Submit a Form $ http > my_file.zipĪlternatively: $ http -download Example 3: Custom HTTP Methodīesides the default GET method, you can use other methods (e.g., PUT, POST, HEAD). You will need to redirect output to a file as follows. You can use http as a file downloader tool. The HTTP request will look like: GET / HTTP/1.1 Note that when HTTP GET method is used, you don't need to specify any HTTP method. $ http User-Agent:Xmodulo/1.0 Referer: MyParam:Foo For example, let's send an HTTP GET request to with custom user-agent ( /1.0) and referer ( ), as well as a custom header ( MyParam:Foo). You can set custom headers in the format of. In the rest of this article, let me show several useful examples of http command. Once you install HTTPie, you can invoke it by typing http command. For Debian, Ubuntu or Linux Mint: $ sudo apt-get install httpieįirst, enable EPEL repository and then run: $ sudo yum install httpieįor any Linux distribution, an alternative installation method is to use pip. Even better, it comes as a prebuilt package on most Linux distributions. HTTPie is written in Python, so you can install it pretty much everywhere (Linux, MacOSX, Windows). In this post, let me review HTTPie, and show you what I mean by HTTPie being a user-friendly alternative of wget and curl. ![]() After all, choice is the best thing about Linux. No need to be loyal and religious about what's being replaced. If I've found a user-friendly alternative of a tool, I don't see any problem adopting the easy to use version in my work environment to save my precious time. For developers or end-users, however, I would say it's all about productivity. This view has merit especially if you are a system admin who works with many different hardware boxes. I know some of you will be skeptical about replacing a ubiquitously available, perfectly good tool such as wget or curl with totally unheard of software. It also displays responses in colorized formats for readability, and offers nice goodies like excellent JSON support and persistent sessions to streamline your workflows. For that, HTTPie comes with expressive, yet very simple and intuitive syntax. Its main goal is to make command-line interaction of a web server as human-friendly as possible. Unless you are well versed in the nitty and gritty details of their syntax, these tools are nothing more than simple web downloaders for you.īilled as a "curl-like tool for humans," HTTPie is designed to improve on wget and curl in terms of usability. However, even powerful tools like these are only as good as your knowledge of how to use them. With extensive command-line options, both of these tools can handle a variety of non-interactive web access use cases (e.g., multi-file download, custom HTTP headers with wget and curl). If you often need to access a web server non-interactively in a terminal environment (e.g., download a file from the web, or test REST-ful web service APIs), chances are that wget or curl is your go-to tool. What is a good alternative to wget or curl on Linux
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |