当前位置: 萬仟网 > IT编程>数据库>MSSQL > Apifox Echo学习curl httpie 命令使用详解

Apifox Echo学习curl httpie 命令使用详解

2022年09月18日 MSSQL 我要评论
正文curl,用于发送请求的命令行工具,一个 http 请求客户端(实际上它也可以做 ftp/scp/telnet 协议的事情,可类比于浏览器中的 fetch。curl 是最为流行的 http 请求命

正文 

curl,用于发送请求的命令行工具,一个 http 请求客户端(实际上它也可以做 ftp/scp/telnet 协议的事情,可类比于浏览器中的 fetch。

curl 是最为流行的 http 请求命令行工具,在谷歌浏览器控制台的网络面板中,可将当前请求转化为 curl

在学习及调试 http 的过程中,可结合 curlapifo echo 一同使用。

apifox echoapifox 出品的一款 http 简单的接口请求和返回数据服务,可以模拟各种接口请求参数和返回数据的情况,供开发人员和测试人员学习测试 api 使用。

curl

直接发送 get 请求:

$ curl ifconfig.me
118.73.227.215

curl --request

--request/-x,指定请求方法,如 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 发送 head 请求,只需要返回 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,查看发送报文及 tls handshake 的详细。

$ 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,追踪重定向。

# 重定向两次后请求到数据
$ curl --location http://zhihu.com
# 可使用 --head,查看到三次响应
$ curl --head --location http://zhihu.com

httpie && examples

httpie 是现代化更为流行的一个 http 客户端,支持色彩、json 等。

# 发送 json 数据给服务器端,httpie 比 curl 方便很多,不需要自己手写 header,curl 默认为 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"}'
# 发送 form 数据给服务器端,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 &lt; 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 中,还可以将请求直接转化为命令行。

结束

  • curl/httpie 如何发送一个 get 请求
  • curl/httpie 如何发送 json 数据给服务器端
  • curl/httpie 如何发送 form 数据给服务器端
  • curl/httpie 如何追踪重定向路径
  • curl/httpie 如何仅返回 response header

以上就是apifox echo学习curl httpie 命令使用详解的详细内容,更多关于apifox echo命令curl httpie 的资料请关注萬仟网其它相关文章!

(1)
打赏 微信扫一扫 微信扫一扫

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。

发表评论

验证码:
Copyright © 2017-2022  萬仟网 保留所有权利. 琼ICP备2022007597号