httpbin 使用
一、httpbin 介绍
httpbin这个网站能测试 HTTP 请求和响应的各种信息,比如 cookie、ip、headers 和登录验证等,且支持 GET、POST 等多种方法,对 web 开发和测试很有帮助。它用 Python + Flask 编写,是一个开源项目。
官方网站:
http://httpbin.org/
开源地址:
https://github.com/Runscope/httpbin
二、httpbin 安装
docker pull kennethreitz/httpbin
docker run -p 80:80 kennethreitz/httpbin
三、httpbin 使用
1、http 请求方法
"Host": "httpbin.org",
"User-Agent": "curl/7.29.0",
"X-Amzn-Trace-Id": "Root=1-5ffff632-0fc3f828798d4ea17a6aeca9"
"origin": "49.233.250.178",
"url": "http://httpbin.org/get"
#模拟post 请求
# curl -XPOST http://httpbin.org/post
#模拟delete 请求
# curl -XDELETE http://httpbin.org/delete
#模拟put 请求
# curl -XPUT http://httpbin.org/put
#模拟patch 请求
# curl -XPATCH http://httpbin.org/patch
2、http 认证
# curl --basic -u test:123456 "http://httpbin.org/basic-auth/test/123456"
"authenticated": true,
"user": "test"
#bearer
curl -X GET "http://httpbin.org/bearer" -H "Authorization: Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"
#diest-auth
curl --digest --user test:123456 http://httpbin.org/digest-auth/aaa/test/123456
#hidden-basic-auth
curl http://httpbin.org/hidden-basic-auth/test/123456
3、http 状态码
# curl http://httpbin.org/status/408 -I
HTTP/1.1 408 REQUEST TIMEOUT
Date: Thu, 14 Jan 2021 09:03:11 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
4、http 请求头检查
"Host": "httpbin.org",
"User-Agent": "curl/7.29.0",
"X-Amzn-Trace-Id": "Root=1-60000903-391514281b4af9d352dc3f8d"
#获取ua
# curl http://httpbin.org/user-agent
"user-agent": "curl/7.29.0"
5、http 响应头检查
#获取base64
# curl http://httpbin.org/base64/aaa
Incorrect Base64 data try: SFRUUEJJTiBpcyBhd2Vzb21l
#获取指定bytes
curl http://httpbin.org/bytes/9999 -I
#指定延时
curl http://httpbin.org/delay/10 -I
#drip
#返回一个links
curl http://httpbin.org/links/1/1
#获取range
curl http://httpbin.org/range/100 -I
#指定二进制大小
curl http://httpbin.org/stream-bytes/100
#指定流大小
curl http://httpbin.org/stream/100
#获取uuid
curl http://httpbin.org/uuid
8、http cookies
# 设置cookies
curl http://httpbin.org/cookies/set
curl http://httpbin.org/cookies/set/a/111
9、http 图片
#获取图片
# curl http://httpbin.org/image
{"message": "Client did not request a supported media type.", "accept": ["image/webp", "image/svg+xml", "image/jpeg", "image/png", "image/*"]}
#获取 jpeg
curl http://httpbin.org/image/jpeg -I
#获取 png
curl http://httpbin.org/image/png -I
#获取 svg
curl http://httpbin.org/image/svg -I
#获取webp
curl http://httpbin.org/image/webp -I
10、 http 重定向
curl http://httpbin.org/redirect/2 -v
curl http://httpbin.org/relative-redirect/2 -v
11、 http anything