当前位置: 首页 > news >正文

httpie使用详解

语法:

http [--json] [--form] [--pretty {all,colors,format,none}]
     [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
     [--all] [--history-print WHAT] [--stream] [--output FILE]
     [--download] [--continue]
     [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
     [--auth USER[:PASS]] [--auth-type {basic,digest}]
     [--proxy PROTOCOL:PROXY_URL] [--follow]
     [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
     [--check-status] [--verify VERIFY]
     [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
     [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
     [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
     [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]

简写就是:

$ http [flags] [METHOD] URL [ITEM [ITEM]]

METHOD
如果不带METHOD参数,这默认为GET(没有附带请求参数)或POST(附带请求参数,默认以json格式传输)

$ http example.org               # => GET
$ http example.org hello=world   # => POST

URL
默认协议为 http://,如果主机是localhost,还可以如下简写:

$ http :3000                    # => http://localhost:3000
$ http :/foo                    # => http://localhost/foo

另外可以使用param==value语法像url添加参数,所产生的效果就是浏览器中通过&连接的参数,注意区分POST方法所使用的param=value语法

http www.google.com search=='HTTPie logo' tbm==isch

创建更方便https的命令

alias https='http --default-scheme=https'

Request items

Item TypeDescriptione.g
HTTP Headers Name:Value Arbitrary HTTP headerX-API-Token:123
URL parameters name==value Appends the given name/value pair as a query string parameter to the URL. The == separator is used.
Data Fields field=value, field=@file.txt Request data fields to be serialized as a JSON object (default), or to be form-encoded (--form, -f).``
Raw JSON fields field:=json, field:=@file.json Useful when sending JSON and one or more fields need to be a Boolean, Number, nested Object, or an Array meals:='["ham","spam"]' or pies:=[1,2,3] (note the quotes).
Form File Fields field@/dir/file Only available with --form, -f. The presence of a file field results in a multipart/form-data request.screenshot@~/Pictures/img.png.
``
``
``
``

json

param=value格式的参数全部会转换成json格式传输,并且value全是字符串

http POST httpbin.org/anything name=John email=john@example.org age=26

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 575
Content-Type: application/json
Date: Tue, 05 Dec 2017 05:03:10 GMT
Server: meinheld/0.6.1
Via: 1.1 vegur
X-Powered-By: Flask
X-Processed-Time: 0.000778913497925

{
    "args": {},
    "data": "{\"name\": \"John\", \"email\": \"john@example.org\", \"age\": \"26\"}",
    "files": {},
    "form": {},
    "headers": {
        "Accept": "application/json, */*",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "close",
        "Content-Length": "58",
        "Content-Type": "application/json",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/0.9.9"
    },
    "json": {
        "age": "26",
        "email": "john@example.org",
        "name": "John"
    },
    "method": "POST",
    "origin": "183.234.62.33",
    "url": "http://httpbin.org/anything"
}

非字符串字段则使用 := 分隔符, which allows you to embed raw JSON into the resulting object. Text and raw JSON files can also be embedded into fields using =@ and :=@:

 /tmp  cat addr.json
{
  "home":"home addr",
  "school":"school addr"
}
 /tmp  cat about.txt
this is about


http POST httpbin.org/anything name=John email=john@example.org \
> age:=29 married:=false hobbies:='["http", "pies"]' \  \  # Raw JSON
> about=@about.txt \                                       # Embed text file
> addr:=@addr.json                                         # Embed JSON file
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 915
Content-Type: application/json
Date: Tue, 05 Dec 2017 05:10:58 GMT
Server: meinheld/0.6.1
Via: 1.1 vegur
X-Powered-By: Flask
X-Processed-Time: 0.00129795074463

{
    "args": {},
    "data": "{\"name\": \"John\", \"email\": \"john@example.org\", \"age\": 29, \"married\": false, \"hobbies\": [\"http\", \"pies\"], \"about\": \"this is about \\n\", \"addr\": {\"home\": \"home addr\", \"school\": \"school addr\"}}",
    "files": {},
    "form": {},
    "headers": {
        "Accept": "application/json, */*",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "close",
        "Content-Length": "188",
        "Content-Type": "application/json",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/0.9.9"
    },
    "json": {
        "about": "this is about \n",
        "addr": {
            "home": "home addr",
            "school": "school addr"
        },
        "age": 29,
        "email": "john@example.org",
        "hobbies": [
            "http",
            "pies"
        ],
        "married": false,
        "name": "John"
    },
    "method": "POST",
    "origin": "183.234.62.33",
    "url": "http://httpbin.org/anything"
}

相关文章:

  • 程序猿的日常——SpringMVC系统架构与流程回顾
  • Web监听器导图详解
  • 如何成为好的系统分析员
  • 分布式监控系统Zabbix3.2给异常添加邮件报警
  • 如何保证用户密码安全
  • Lintcode123 Word Search solution 题解
  • The Little Prince-12/08
  • React中路由传参及接收参数的方式
  • 移动硬盘做pe启动盘
  • Java爬虫——人人网模拟登录
  • 服务器小白-MYSQL基础安装配置
  • [译] 听说你想学 React.js ?
  • 学习CSS的思路(转)
  • Js基础知识学习
  • 对PostgreSQL源代码中的is_pushed_down的理解
  • 2018以太坊智能合约编程语言solidity的最佳IDEs
  • bearychat的java client
  • Cookie 在前端中的实践
  • CSS3 变换
  • css布局,左右固定中间自适应实现
  • JS实现简单的MVC模式开发小游戏
  • Mac 鼠须管 Rime 输入法 安装五笔输入法 教程
  • orm2 中文文档 3.1 模型属性
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • Promise面试题,控制异步流程
  • Python十分钟制作属于你自己的个性logo
  • React的组件模式
  • Storybook 5.0正式发布:有史以来变化最大的版本\n
  • tensorflow学习笔记3——MNIST应用篇
  • webpack+react项目初体验——记录我的webpack环境配置
  • 包装类对象
  • 高度不固定时垂直居中
  • 理解在java “”i=i++;”所发生的事情
  • 力扣(LeetCode)22
  • 为视图添加丝滑的水波纹
  • 一些css基础学习笔记
  • ​secrets --- 生成管理密码的安全随机数​
  • #微信小程序:微信小程序常见的配置传值
  • (react踩过的坑)Antd Select(设置了labelInValue)在FormItem中initialValue的问题
  • (ZT)薛涌:谈贫说富
  • (二)springcloud实战之config配置中心
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (五)网络优化与超参数选择--九五小庞
  • (一)Dubbo快速入门、介绍、使用
  • (一)eclipse Dynamic web project 工程目录以及文件路径问题
  • ***监测系统的构建(chkrootkit )
  • .NET CORE 2.0发布后没有 VIEWS视图页面文件
  • .Net Core webapi RestFul 统一接口数据返回格式
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .NET MVC之AOP
  • .vollhavhelp-V-XXXXXXXX勒索病毒的最新威胁:如何恢复您的数据?
  • @AliasFor注解
  • @for /l %i in (1,1,10) do md %i 批处理自动建立目录
  • [ C++ ] STL---stack与queue
  • []我的函数库