Apifox?Echo學(xué)習(xí)curl?httpie?命令使用詳解
正文
curl
,用于發(fā)送請(qǐng)求的命令行工具,一個(gè) HTTP 請(qǐng)求客戶端(實(shí)際上它也可以做 FTP/SCP/TELNET 協(xié)議的事情,可類比于瀏覽器中的 fetch。
curl
是最為流行的 HTTP 請(qǐng)求命令行工具,在谷歌瀏覽器控制臺(tái)的網(wǎng)絡(luò)面板中,可將當(dāng)前請(qǐng)求轉(zhuǎn)化為 curl
。
在學(xué)習(xí)及調(diào)試 HTTP 的過(guò)程中,可結(jié)合 curl
與 Apifo Echo 一同使用。
Apifox Echo
是 Apifox 出品的一款 HTTP 簡(jiǎn)單的接口請(qǐng)求和返回?cái)?shù)據(jù)服務(wù),可以模擬各種接口請(qǐng)求參數(shù)和返回?cái)?shù)據(jù)的情況,供開(kāi)發(fā)人員和測(cè)試人員學(xué)習(xí)測(cè)試 API 使用。
curl
直接發(fā)送 GET 請(qǐng)求:
$ curl ifconfig.me 118.73.227.215
curl --request
--request/-X
,指定請(qǐng)求方法,如 POST
等。
$ curl \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <TOKEN>" \ https://api.github.com/repos/OWNER/REPO/issues \ -d '{"title":"Found a bug","body":"I'\''m having a problem with this.","assignees":["octocat"],"milestone":1,"labels":["bug"]}' $ curl https://echo.apifox.com/post -X POST -H "a: 3" -H "b: 4" { "args": {}, "data": "", "files": {}, "form": {}, "headers": { "A": "3", "Accept": "*/*", "B": "4", "Connection": "close", "Host": "echo.apifox.com", "User-Agent": "curl/7.79.1" }, "json": null, "origin": "118.113.0.137", "url": "https://echo.apifox.com/post" }
curl --head
--head/-I
發(fā)送 HEAD 請(qǐng)求,只需要返回 Response Header。
$ curl --head https://shanyue.tech HTTP/2 200 server: Tengine content-type: text/html; charset=utf-8 content-length: 33229 vary: Accept-Encoding date: Tue, 21 Jun 2022 05:54:24 GMT vary: Accept-Encoding x-oss-request-id: 62B15D1050ED1C32320FE906 x-oss-cdn-auth: success accept-ranges: bytes etag: "F540C0D57CDB57215AF11970EF4AAEF6" last-modified: Wed, 23 Mar 2022 14:57:44 GMT x-oss-object-type: Normal x-oss-hash-crc64ecma: 8545542358272103335 x-oss-storage-class: Standard x-oss-meta-mtime: 1648047444.796073379 cache-control: no-cache content-md5: 9UDA1XzbVyFa8Rlw70qu9g== x-oss-server-time: 27 ali-swift-global-savetime: 1655790864 via: cache12.l2cn3051[290,290,200-0,M], cache4.l2cn3051[291,0], kunlun6.cn3145[383,382,200-0,M], kunlun3.cn3145[386,0] x-cache: MISS TCP_MISS dirn:-2:-2 x-swift-savetime: Tue, 21 Jun 2022 05:54:24 GMT x-swift-cachetime: 0 timing-allow-origin: * eagleid: 791d26a916557908641262834e
curl --include
--include/-i
,打印 Response Header 與 Response Body。
HTTP/1.1 200 OK access-control-allow-origin: * content-type: text/plain; charset=utf-8 content-length: 15 date: Wed, 17 Aug 2022 01:56:20 GMT x-envoy-upstream-service-time: 1 strict-transport-security: max-age=2592000; includeSubDomains server: istio-envoy Via: 1.1 google 222.222.222.113%
curl --verbose
--verbose/-v
,查看發(fā)送報(bào)文及 TLS handshake 的詳細(xì)。
$ curl -vvv --head https://shanyue.tech * Rebuilt URL to: https://shanyue.tech/ * Trying 218.91.183.88... * TCP_NODELAY set * Connected to shanyue.tech (218.91.183.88) port 443 (#0) * ALPN, offering h3 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * TLSv1.3 (OUT), TLS handshake, Client hello (1): * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, [no content] (0): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * TLSv1.3 (IN), TLS handshake, [no content] (0): * TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, [no content] (0): * TLSv1.3 (IN), TLS handshake, CERT verify (15): * TLSv1.3 (IN), TLS handshake, [no content] (0): * TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.3 (OUT), TLS handshake, [no content] (0): * TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN, server accepted to use h3 * Server certificate: * subject: CN=shanyue.tech * start date: Feb 5 00:00:00 2022 GMT * expire date: Feb 6 23:59:59 2023 GMT * subjectAltName: host "shanyue.tech" matched cert's "shanyue.tech" * issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=Encryption Everywhere DV TLS CA - G1 * SSL certificate verify ok. * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * TLSv1.3 (OUT), TLS app data, [no content] (0): * TLSv1.3 (OUT), TLS app data, [no content] (0): * TLSv1.3 (OUT), TLS app data, [no content] (0): * Using Stream ID: 1 (easy handle 0x55c5a8e24690) * TLSv1.3 (OUT), TLS app data, [no content] (0): > HEAD / HTTP/2 > Host: shanyue.tech > User-Agent: curl/7.61.1 > Accept: */* > * TLSv1.3 (IN), TLS handshake, [no content] (0): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS handshake, [no content] (0): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS app data, [no content] (0): * Connection state changed (MAX_CONCURRENT_STREAMS == 128)! * TLSv1.3 (OUT), TLS app data, [no content] (0): * TLSv1.3 (IN), TLS app data, [no content] (0): < HTTP/2 200 HTTP/2 200 < server: Tengine server: Tengine < content-type: text/html; charset=utf-8 content-type: text/html; charset=utf-8 < content-length: 33229 content-length: 33229 < vary: Accept-Encoding vary: Accept-Encoding < date: Tue, 21 Jun 2022 06:02:59 GMT date: Tue, 21 Jun 2022 06:02:59 GMT < vary: Accept-Encoding vary: Accept-Encoding < x-oss-request-id: 62B15F13F15BB231391FB3A8 x-oss-request-id: 62B15F13F15BB231391FB3A8 < x-oss-cdn-auth: success x-oss-cdn-auth: success < accept-ranges: bytes accept-ranges: bytes < etag: "F540C0D57CDB57215AF11970EF4AAEF6" etag: "F540C0D57CDB57215AF11970EF4AAEF6" < last-modified: Wed, 23 Mar 2022 14:57:44 GMT last-modified: Wed, 23 Mar 2022 14:57:44 GMT < x-oss-object-type: Normal x-oss-object-type: Normal < x-oss-hash-crc64ecma: 8545542358272103335 x-oss-hash-crc64ecma: 8545542358272103335 < x-oss-storage-class: Standard x-oss-storage-class: Standard < x-oss-meta-mtime: 1648047444.796073379 x-oss-meta-mtime: 1648047444.796073379 < cache-control: no-cache cache-control: no-cache < content-md5: 9UDA1XzbVyFa8Rlw70qu9g== content-md5: 9UDA1XzbVyFa8Rlw70qu9g== < x-oss-server-time: 3 x-oss-server-time: 3 < ali-swift-global-savetime: 1655791379 ali-swift-global-savetime: 1655791379 < via: cache24.l2et15-1[66,66,200-0,M], cache44.l2et15-1[67,0], cache27.cn4056[128,128,200-0,M], cache64.cn4056[130,0] via: cache24.l2et15-1[66,66,200-0,M], cache44.l2et15-1[67,0], cache27.cn4056[128,128,200-0,M], cache64.cn4056[130,0] < x-cache: MISS TCP_MISS dirn:-2:-2 x-cache: MISS TCP_MISS dirn:-2:-2 < x-swift-savetime: Tue, 21 Jun 2022 06:02:59 GMT x-swift-savetime: Tue, 21 Jun 2022 06:02:59 GMT < x-swift-cachetime: 0 x-swift-cachetime: 0 < timing-allow-origin: * timing-allow-origin: * < eagleid: 088432cc16557913793393217e eagleid: 088432cc16557913793393217e < * Connection #0 to host shanyue.tech left intact
curl --location
--location/-L
,追蹤重定向。
# 重定向兩次后請(qǐng)求到數(shù)據(jù) $ curl --location http://zhihu.com # 可使用 --head,查看到三次響應(yīng) $ curl --head --location http://zhihu.com
httpie && examples
httpie 是現(xiàn)代化更為流行的一個(gè) HTTP 客戶端,支持色彩、JSON 等。
# 發(fā)送 JSON 數(shù)據(jù)給服務(wù)器端,httpie 比 curl 方便很多,不需要自己手寫 header,curl 默認(rèn)為 application/x-www-form-urlencoded $ http POST https://echo.apifox.com/post "a: 3" name=shanyue $ curl -X POST https://echo.apifox.com/post -H "a: 3" -H "content-type: application/json" -d '{"name": "shanyue"}' # 發(fā)送 Form 數(shù)據(jù)給服務(wù)器端,curl/httpie 都比較方便 $ http POST https://echo.apifox.com/post "a: 3" name=shanyue $ curl -X POST https://echo.apifox.com/post -H "a: 3" -d name=shanyue # 上傳文件 $ http POST https://echo.apifox.com/post < Readme.md $ curl -X POST https://echo.apifox.com/post -H "content-type: application/json" -d @Readme.md # multipart 上傳文件 $ http --multipart https://echo.apifox.com/post a=3 b@'Readme.md'
在 Apifox Echo 中,還可以將請(qǐng)求直接轉(zhuǎn)化為命令行。
結(jié)束
- curl/httpie 如何發(fā)送一個(gè) GET 請(qǐng)求
- curl/httpie 如何發(fā)送 JSON 數(shù)據(jù)給服務(wù)器端
- curl/httpie 如何發(fā)送 FORM 數(shù)據(jù)給服務(wù)器端
- curl/httpie 如何追蹤重定向路徑
- curl/httpie 如何僅返回 Response Header
以上就是Apifox Echo學(xué)習(xí)curl httpie 命令使用詳解的詳細(xì)內(nèi)容,更多關(guān)于Apifox Echo命令curl httpie 的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
通過(guò)自定義字段重新排序 WordPress 文章方法
在本文中,我將向您展示如何通過(guò)自定義字段更改文章的順序。WordPress 中文章的默認(rèn)順序基于發(fā)布日期,并按時(shí)間倒序顯示。這意味著它將在頂部顯示最新的文章。2021-09-09git如何還原到某次commit并強(qiáng)制推送遠(yuǎn)程
這篇文章主要介紹了git如何還原到某次commit并強(qiáng)制推送遠(yuǎn)程的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09VSCode 遠(yuǎn)程登錄開(kāi)發(fā)(帶免密)
這篇文章主要介紹了VSCode 遠(yuǎn)程登錄開(kāi)發(fā)(帶免密),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05關(guān)于target目錄在idea沒(méi)顯示的問(wèn)題
這篇文章主要介紹了關(guān)于target目錄在idea沒(méi)顯示的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11使用.gitignore文件簡(jiǎn)化Git倉(cāng)庫(kù)管理
.gitignore文件用于指定在git中應(yīng)該被忽略的文件或目錄,前端的node_modules目錄包含大量文件,如果將其添加到版本管理系統(tǒng)中,會(huì)使倉(cāng)庫(kù)變得龐大,不利于倉(cāng)庫(kù)的管理,本文介紹了使用.gitignore文件來(lái)簡(jiǎn)化你的Git倉(cāng)庫(kù)管理2023-10-10