日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
分享一個巨好用的 HTTP命令行寶藏工具

HTTPie 是一個命令行 HTTP 客戶端。它的目標(biāo)是使 CLI 與 Web 服務(wù)的交互盡可能人性化。HTTPie 設(shè)計用于測試、調(diào)試以及通常與 API 和 HTTP 服務(wù)器交互。http 和 https 的命令允許創(chuàng)建和發(fā)送任意 HTTP 請求。HTTPie 整體采用簡單自然的語法,并提供格式化和彩色輸出。

創(chuàng)新互聯(lián)建站專注于巨野企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城開發(fā)。巨野網(wǎng)站建設(shè)公司,為巨野等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)

主要特點

  • 富有表現(xiàn)力和直觀的語法
  • 格式化和彩色終端輸出
  • 內(nèi)置 JSON 支持
  • 表格和文件上傳
  • HTTPS、代理和身份驗證
  • 任意請求數(shù)據(jù)
  • 自定義標(biāo)題
  • 持續(xù)Sessions
  • 類似 Wget 的下載
  • Linux、macOS、Windows 和 FreeBSD 支持
  • 插件
  • 文檔
  • 測試覆蓋率

安裝

macOS

Homebrew

安裝 Homebrew 可以看它的安裝教程[1].

安裝 httpie

brew update
brew install httpie

升級 httpie

brew update
brew upgrade httpie

Windows

Chocolatey

安裝 Chocolatey 可以看它的 安裝教程[2].

安裝 httpie

choco install httpie

升級 httpie

choco upgrade httpie

Linux

Snapcraft (Linux)

安裝 Snapcraft 可以看它的 安裝教程[3].

安裝 httpie

snap install httpie

升級 httpie

snap refresh httpie

Debian and Ubuntu

也適用于其他 Debian 衍生發(fā)行版,如 MX Linux、Linux Mint、deepin、Pop!_OS、KDE neon、Zorin OS、elementary OS、Kubuntu、Devuan、Linux Lite、Peppermint OS、Lubuntu、antiX、Xubuntu 等。

安裝 httpie

apt update
apt install httpie

升級 httpie

apt update
apt upgrade httpie

FreeBSD

安裝 httpie

pkg install www/py-httpie

升級 httpie

pkg upgrade www/py-httpie

安裝測試版本

大家還可以直接從masterGitHub 上的分支安裝最新的未發(fā)布開發(fā)版本。它是未來穩(wěn)定版本的正在進行中的工作,因此體驗可能不會那么順利。

大家可以使用以下命令在 Linux、macOS、Windows 或 FreeBSD 上安裝pip:

python -m pip install --upgrade https://github.com/httpie/httpie/archive/master.tar.gz

或者在 macOS 和 Linux 上,使用 Homebrew:

brew uninstall --force httpie
brew install --HEAD httpie

甚至在 macOS 和 Linux 上,使用 Snapcraft:

snap remove httpie
snap install httpie --edge

驗證是否擁有帶有后綴的當(dāng)前開發(fā)版本標(biāo)識符.dev0,例如:

http --version
#3.0.3.dev0

用法

Hello World:

https httpie.io/hello

獲取用法:

http [flags] [METHOD] URL [ITEM [ITEM]]
http --help

舉例

自定義HTTP 方法、HTTP Header和JSON數(shù)據(jù):

http PUT pie.dev/put X-API-Token:123 name=John

提交 forms:

http -f POST pie.dev/post hello=World

查看使用輸出選項之一發(fā)送的請求:

http -v pie.dev/get

在不發(fā)送的情況下通過使用離線模式構(gòu)建和打印請求:

http --offline pie.dev/post hello=offline

使用重定向上傳文件:

http pie.dev/post < files/data.json

下載文件并通過重定向輸出保存:

http pie.dev/image/png > image.png

使用命名Sessions使對同一主機的請求之間的通信的某些方面保持持久:

http --session=logged-in -a username:password pie.dev/get API-Key:123
http --session=logged-in pie.dev/headers

設(shè)置自定義Host Header以解決丟失的 DNS 記錄:

http localhost:8000 Host:example.com

HTTP方法

HTTP 方法的名稱就在 URL 參數(shù)之前:

http DELETE pie.dev/delete

這看起來與發(fā)送的實際相似Request-Line:

DELETE /delete HTTP/1.1

除了標(biāo)準(zhǔn)方法(GET、POST、HEAD、PUT、PATCH、DELETE等)之外,還可以使用自定義方法名稱,例如:

http AHOY pie.dev/post

對于請求方法可以包含正文沒有任何限制,發(fā)送一個空POST請求:

http POST pie.dev/post

還可以發(fā)出GET包含正文的請求:

http GET pie.dev/get hello=world

可選GET和POST

該METHOD參數(shù)是可選的,當(dāng)你不指定它時,HTTPie 默認(rèn)為:

  • GET: 對于沒有正文的請求
  • POST: 對于帶有正文的請求

這里我們沒有指定任何請求數(shù)據(jù),所以兩個命令將發(fā)送相同的GET請求:

http GET pie.dev/get
http pie.dev/get

另一方面,我們可以通過兩個命令將發(fā)出相同的POST請求:

http pie.dev/post hello=world

請求網(wǎng)址

HTTPie 執(zhí)行請求所需的唯一信息是 URL。

默認(rèn)方案是http://并且可以從參數(shù)中省略:

http example.org
#→ http://example.org

HTTPie 還安裝了一個https可執(zhí)行文件,其中默認(rèn)方案是https://:

https example.org
#→ https://example.org

當(dāng)把 URL 粘貼到終端時,甚至可以保留://URL 參數(shù)中的位,以將 URL 快速轉(zhuǎn)換為 HTTPie 調(diào)用,只需在協(xié)議名稱后添加一個空格即可。

https ://example.org #→ https://example.org

網(wǎng)址快捷方式localhost

支持類似 curl 的 localhost 簡寫。這意味著,例如,:3000將擴展為http://localhost:3000 如果省略端口,則假定端口 80。

http :/foo
GET /foo HTTP/1.1
Host: localhost
http :3000/bar
GET /bar HTTP/1.1
Host: localhost:3000
http :
GET / HTTP/1.1
Host: localhost

JSON

JSON 是現(xiàn)代 Web 服務(wù)的通用語,也是HTTPie 默認(rèn)使用的隱式內(nèi)容類型。

簡單的例子:

http PUT pie.dev/put name=John email=john@example.org
PUT / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json
Host: pie.dev

{
"name": "John",
"email": "john@example.org"
}

默認(rèn)行為

如果命令中包含一些數(shù)據(jù)請求項,則默認(rèn)將它們序列化為 JSON 對象。HTTPie 還自動設(shè)置以下Header,這兩個Header都可以被覆蓋:

Content-Type : application/json

Accept : application/json, /;q=0.5

顯式 JSON

無論是否正在發(fā)送數(shù)據(jù),都可以使用--json, -j顯式設(shè)置Accept為(這是通過通常的Header符號設(shè)置Header的快捷方式:) 。此外,即使響應(yīng)不正確或未知,HTTPie 也會嘗試檢測 JSON 響應(yīng)。application/jsonhttp url Accept:'application/json, /;q=0.5'Content-Typetext/plain

非字符串 JSON 字段

非字符串 JSON 字段使用:=分隔符,它允許將任意 JSON 數(shù)據(jù)嵌入到生成的 JSON 對象中。此外,文本和原始 JSON 文件也可以使用=@和嵌入到字段中:=@:

http PUT pie.dev/put \
name=John \ # String (default)
age:=29 \ # Raw JSON — Number
married:=false \ # Raw JSON — Boolean
hobbies:='["http", "pies"]' \ # Raw JSON — Array
favorite:='{"tool": "HTTPie"}' \ # Raw JSON — Object
bookmarks:=@files/data.json \ # Embed JSON file
description=@files/text.txt # Embed text file
PUT /person/1 HTTP/1.1
Accept: application/json, */*;q=0.5
Content-Type: application/json
Host: pie.dev

{
"age": 29,
"hobbies": [
"http",
"pies"
],
"description": "John is a nice guy who likes pies.",
"married": false,
"name": "John",
"favorite": {
"tool": "HTTPie"
},
"bookmarks": {
"HTTPie": "https://httpie.org",
}
}

:=/:=@語法是 JSON 特定的。大家可以將請求切換為--formor --multipart,并且字符串、浮點數(shù)和數(shù)字值將繼續(xù)被序列化(作為字符串形式的值)。但是,其他 JSON 類型不允許使用--form或--multipart。

形式

提交表單與發(fā)送JSON請求非常相似。通常唯一的區(qū)別是添加--form, -f選項,它確保數(shù)據(jù)字段被序列化為,并Content-Type設(shè)置為application/x-www-form-urlencoded; charset=utf-8. 可以通過配置文件使表單數(shù)據(jù)成為隱式內(nèi)容類型而不是 JSON。

常規(guī)表格

http --form POST pie.dev/post name='John Smith'
POST /post HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8

name=John+Smith

文件上傳表格

如果存在一個或多個文件字段,則序列化和內(nèi)容類型為multipart/form-data:

http -f POST pie.dev/post name='John Smith' cv@~/files/data.xml

上面的請求與提交以下 HTML 表單相同:





請注意,@它用于模擬文件上傳表單字段,而=@只是將文件內(nèi)容嵌入為常規(guī)文本字段值。

上傳文件時,它們的內(nèi)容類型是從文件名中推斷出來的。大家可以手動覆蓋推斷的內(nèi)容類型:

http -f POST pie.dev/post name='John Smith' cv@'~/files/data.bin;type=application/pdf'

multipart/form-data即使沒有任何文件也要執(zhí)行請求,請使用--multipart代替--form:

http --multipart --offline example.org hello=world
POST / HTTP/1.1
Content-Length: 129
Content-Type: multipart/form-data; boundary=c31279ab254f40aeb06df32b433cbccb
Host: example.org

--c31279ab254f40aeb06df32b433cbccb
Content-Disposition: form-data; name="hello"

world
--c31279ab254f40aeb06df32b433cbccb--

文件上傳總是流式傳輸以避免大文件的內(nèi)存問題。

默認(rèn)情況下,HTTPie 使用隨機唯一字符串作為多部分邊界,但大家可以使用它--boundary來指定自定義字符串:

http --form --multipart --offline example.org hello=world Content-Type:multipart/letter
POST / HTTP/1.1
Content-Length: 129
Content-Type: multipart/letter; boundary=c31279ab254f40aeb06df32b433cbccb
Host: example.org

--c31279ab254f40aeb06df32b433cbccb
Content-Disposition: form-data; name="hello"

world
--c31279ab254f40aeb06df32b433cbccb--

如果指定自定義Content-Type Header而不包括邊界位,HTTPie 將自動將邊界值(顯式指定或自動生成)添加到 Headers:

http --form --multipart --offline example.org hello=world Content-Type:multipart/letter
POST / HTTP/1.1
Content-Length: 129
Content-Type: multipart/letter; boundary=c31279ab254f40aeb06df32b433cbccb
Host: example.org

--c31279ab254f40aeb06df32b433cbccb
Content-Disposition: form-data; name="hello"

world
--c31279ab254f40aeb06df32b433cbccb--

HTTP Headers

要設(shè)置自定義 Headers,可以通過使用以下Header:Value符號:

http pie.dev/headers User-Agent:Bacon/1.0 'Cookie:valued-visitor=yes;foo=bar' \
X-Foo:Bar Referer:https://httpie.org/
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Cookie: valued-visitor=yes;foo=bar
Host: pie.dev
Referer: https://httpie.org/
User-Agent: Bacon/1.0
X-Foo: Bar

默認(rèn)請求headers

HTTPie 設(shè)置了幾個默認(rèn)Header:

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: HTTPie/
Host:

其中任何一個都可以被覆蓋,其中一些可以取消設(shè)置(見下文)。

具有相同名稱的多個Header Value

如果請求是使用共享相同名稱的多個Header發(fā)送的,則 HTTPie 將單獨發(fā)送它們。

http --offline example.org Cookie:one Cookie:two
GET / HTTP/1.1
Cookie: one
Cookie: two

也可以傳遞單個header value pair,其中值是Header Value的逗號分隔列表。然后客戶端會將其作為單個header發(fā)送。

http --offline example.org Numbers:one,two
GET / HTTP/1.1
Numbers: one,two

另外,如果當(dāng)前Sessions包含任何header,則它們將在發(fā)送請求時被單獨的命令覆蓋,而不是被連接在一起。

限制響應(yīng)Header

這些--max-headers=n選項允許控制 HTTPie 在放棄之前讀取的Header數(shù)量(默認(rèn)值0,即沒有限制)。

http --max-headers=100 pie.dev/get

Cookies

HTTP 客戶端將 cookie 作為常規(guī)HTTP Header發(fā)送到服務(wù)器。這意味著,HTTPie 不提供任何用于指定 cookie 的特殊語法——使用通常的Header:Value符號:

發(fā)送一個 cookie:

http pie.dev/cookies Cookie:sessionid=foo
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: sessionid=foo
Host: pie.dev
User-Agent: HTTPie/0.9.9

發(fā)送多個 cookie(注意:header被引用以防止 shell 解釋;):

http pie.dev/cookies 'Cookie:sessionid=foo;another-cookie=bar'
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: sessionid=foo;another-cookie=bar
Host: pie.dev
User-Agent: HTTPie/0.9.9

HTTPS

服務(wù)器 SSL 證書驗證

跳過主機的 SSL 證書驗證,可以通過--verify=no(默認(rèn)為yes):

http --verify=no https://pie.dev/get

自定義 CA 包

大家還可以使用--verify=設(shè)置自定義 CA 包路徑:

http --verify=/ssl/custom_ca_bundle https://example.org

客戶端 SSL 證書

要將客戶端證書用于 SSL 通信,可以使用以下命令傳遞證書文件的路徑--cert:

http --cert=client.pem https://example.org

如果私鑰不包含在證書文件中,大家可以通過以下方式傳遞密鑰文件的路徑--cert-key:

http --cert=client.crt --cert-key=client.key https://example.org

SSL 版本

使用該--ssl=選項指定要使用的所需協(xié)議版本。這將默認(rèn)為 SSL v2.3,它將協(xié)商服務(wù)器和安裝的 OpenSSL 支持的最高協(xié)議??捎玫膮f(xié)議是ssl2.3, ssl3, tls1, tls1.1, tls1.2, tls1.3. (實際可用的協(xié)議集可能因 OpenSSL 安裝而異。)

#Specify the vulnerable SSL v3 protocol to talk to an outdated server:
http --ssl=ssl3 https://vulnerable.example.org

SSL 密碼

可以使用 指定可用的密碼--ciphers。它應(yīng)該是OpenSSL 密碼列表格式的字符串。

#Specify the vulnerable SSL v3 protocol to talk to an outdated server:
http --ssl=ssl3 https://vulnerable.example.org

Sessions

默認(rèn)情況下,HTTPie 發(fā)出的每個請求都完全獨立于同一主機之前的任何請求。

但是,HTTPie 也通過該--session=SESSION_NAME_OR_PATH選項支持持久Sessions。在Sessions中,自定義HTTP Header Content-(以or開頭的Header除外If-)、身份驗證和cookie(手動指定或由服務(wù)器發(fā)送)在對同一主機的請求之間持續(xù)存在。

#Create a new session:
http --session=./session.json pie.dev/headers API-Token:123
#Inspect / edit the generated session file: cat session.json
#Re-use the existing session — the API-Token header will be set:
http --session=./session.json pie.dev/headers

所有Session數(shù)據(jù),包括憑據(jù)、提示密碼、cookie 數(shù)據(jù)和自定義header都以純文本形式存儲。這意味著Sessions文件也可以在文本編輯器中手動創(chuàng)建和編輯——它們是常規(guī)的 JSON。這也意味著任何有權(quán)訪問Session文件的人都可以讀取它們。

命名Sessions

大家可以為每個主機創(chuàng)建一個或多個命名Sessions。例如,可以通過以下方式創(chuàng)建一個名為user1for的新Sessions pie.dev:

http --session=user1 -a user1:password pie.dev/get X-Foo:Bar

user1從現(xiàn)在開始,可以通過名稱 ( )來引用Sessions。當(dāng)選擇再次使用Sessions時,將自動設(shè)置所有先前指定的身份驗證或 HTTP header:

http --session=user1 pie.dev/get

要創(chuàng)建或重用不同的Sessions,只需指定不同的名稱:

http --session=user2 -a user2:password pie.dev/get X-Bar:Foo

命名Sessions的數(shù)據(jù)存儲在配置sessions目錄子目錄內(nèi)的 JSON 文件中,通常(在 Windows 上)。~/.config/httpie/sessions//.json%APPDATA%\httpie\sessions.json

如果大家在 Unix 機器上執(zhí)行了上述命令,應(yīng)該能夠使用以下命令列出生成的Sessions文件:

ls -l ~/.config/httpie/sessions/pie.dev

匿名Session

可以直接指定Sessions文件的路徑,而不是為其命名。這允許跨多個主機重復(fù)使用Session:

#Create a session:
http --session=/tmp/session.json example.org
#Use the session to make a request to another host:
http --session=/tmp/session.json admin.example.org
#You can also refer to a previously created named session:
http --session=~/.config/httpie/sessions/another.example.org/test.json example.org

在創(chuàng)建匿名Sessions時,請記住始終包含至少一個/,即使Sessions文件位于當(dāng)前目錄中(即--session=./session.json,而不是只是--session=session.json),否則 HTTPie 會采用命名Sessions。

只讀Sessions

要在創(chuàng)建后使用原始Sessions文件而不從請求/響應(yīng)交換中更新它,請指定Sessions名稱 via --session-read-only=SESSION_NAME_OR_PATH。

#If the session file doesn’t exist, then it is created:
http --session-read-only=./ro-session.json pie.dev/headers Custom-Header:orig-value
#But it is not updated:
http --session-read-only=./ro-session.json pie.dev/headers Custom-Header:new-value

參考資料

[1]安裝教程: https://docs.brew.sh/Installation

[2]安裝教程: https://chocolatey.org/install[3]安裝教程: https://snapcraft.io/docs/installing-snapd


當(dāng)前名稱:分享一個巨好用的 HTTP命令行寶藏工具
文章源于:http://m.5511xx.com/article/djhjcco.html