Use interface test command Httpie

Compared to curl command, Httpie provide a clearer friendly interface, and supports authorized agents and other operations

Key Features

  • Intuitive syntax
  • And color format of the output terminal
  • Built-in support for JSON
  • Support and file upload form
  • HTTPS, proxy and authentication
  • Any request data
  • Custom header
  • Persistent sessions
  • Class Wget download
  • Support Python 2.6, 2.7 and 3.x
  • Support for Linux, Mac OS X and Windows
  • Plug
  • File
  • Test coverage

installation method

pip install httpie

Use
Httpie command http,? All options (request method, request header, request data) are separated by a space

  • Request method: the GET / POST / the DELETE / the PUT / ...
    (the default is no data GET, POST request data by default)
  • Request header: in order to :separate, asContent-Type: application/json
  • Request data: to =separate the plurality of parameters separated by spaces, such as name=张三 password=123456when the parameter value is not a string, in :=spaced apart, such as a:=1 b:=true
    request the default type as JSON, use -fwas form type

Examples

  1. GET request (parameters can be written in the url)
http 'http://115.28.108.130:5000/add/?a=1&b=2'

Httpie send a GET request

  1. POST request form classes
http -f 'http://115.28.108.130:5000/api/user/login/' name=张三  password=123456

POST request sent form classes Httpie

  1. JSON format request
http 'http://115.28.108.130:5000/api/user/reg/' name=张三 password=123456

JSON format transmission request Httpie

  1. Carry Cookie
    (intermediate special characters can be used ''in quotes)
http http://115.28.108.130:5000/api/user/getUserList/ Cookie:'PYSESSID=05eac6ba-2eb6-11e9-a130-00163e06e52c;session=eyIwNWVhYzZiYS0yZWI2LTExZTktYTEzMC0wMDE2M2UwNmU1MmMiOnRydWV9.D0Q51A.u9XjrAZb-plUSl01QnNPkGXJPck'

  1. Basic Auth interfaces
    used -a 用户名:密码to transmit Basic Auth interfaces, such as:
http -a superhin001:hanzhichao520 https://api.github.com/user

Httpie Send Basic Auth Interface

Reference article: Sunshine main island: HTTPIE tool Getting Started

Guess you like

Origin www.cnblogs.com/superhin/p/11454945.html