httpie实用指南

Purpose:

  1. 在命令行界面确实需要一款网络工具,但是curl太难用了, 要记忆的参数符号太多了。
  2. 相比于curl这个工具的突出特点是命令看上去更加的人性化, 而且有语法高亮

Feelings:

  1. 相比于curl命令上的变化还挺多的
  2. 而且更加的直观,用官方的话说就是intuitive
  3. 简单的json使用非常的方便

Notes:

  • 官方网站
  • 命令行命令是http
  • http method:
    • httpie支持restful风格的请求
    • ❌如果请求中没有数据就自动发get请求, 如果有就发post请求—这个没实践的时候发现不太对,都发的get请求
    • 如果是其他method,可以按如下方式使用,很类似于http的请求格式:
http DELETE example.org/todos/7
  • Request URL
    • 对localhost有特别的shortcuts,可以省略前面的localhost这个字符串
http :8080/foo
## 以下是回复
GET /foo HTTP/1.1
Host: localhost
  • 可以给https一个别名,方便使用
alias https='http --default-scheme=https'
  • Request Items:通过分隔符去区分各种类型的item,而不是参数选项


    request items
  • JSON, 使用很简洁:
➜  ~ http POST :8080/jsonTest name="kk" age=123
# 以下是回复
HTTP/1.1 200
Content-Length: 34
Content-Type: application/json;charset=UTF-8
Date: Fri, 09 Nov 2018 03:38:31 GMT

server_v_{"name":"kk","age":"123"}
  • Follow Location :To instruct HTTPie to follow the Location header of 30x responses and show the final response instead, use the --follow, -F option:
$ http --follow httpbin.org/redirect/3
  • Download, 像wget一样简单,很实用, 另外下载的时候可以使用 > 来重定向文件
http --download https://github.com/jakubroztocil/httpie/archive/master.tar.gz
  • Resuming downloads :If --output, -o is specified, you can resume a partial download using the --continue, -c option. This only works with servers that support Range requests and 206 Partial Content responses. If the server doesn't support that, the whole file will simply be downloaded:
$ http -dco file.zip example.org/file

ps: 涉及到localhost的用例需要自己搭建本地服务

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html...
    梁行之阅读 1,162评论 0 0
  • 英文文档,一开始我也是抗拒的,边翻译边看,也就花费了1个小时基本就阅读过了,我的英文基础其实很差。附上链接:链接:...
    lonecolonel阅读 10,014评论 3 1
  • =========================================================...
    lavor阅读 3,508评论 0 5
  • Nginx 的配置文件使用的就是一门微型的编程语言,许多真实世界里的 Nginx 配置文件其实就是一个一个的小程序...
    SkTj阅读 4,248评论 0 7
  • 二超四月/ 有些人是蜗牛 驮着壳 装着伤 世界小小 不急不慢 有些人是乌龟 害怕打扰 又期待遇见 走近与不走进 都...
    二超四月阅读 256评论 0 3