http://httpbin.org 测试接口解析

介绍:

HTTP库的测试一般来说较为繁琐,一些同学较为熟悉的RequestBin虽然好用,但只能测试POST,且无法控制其response。HTTPBin是以Python+Flask写的一款工具,它cover了各类的HTTP场景,且每个接口一定都有返回。

安装方法

使用pip工具分别安装httpbin与guicorn,guicorn是一个wsgi http服务器,详见guicorn 是什么

#安装pip工具
[root@localhost ~]# wget https://bootstrap.pypa.io/get-pip.py
[root@localhost ~]# python get-pip.py
#分别使用pip工具安装guicorn与httpbin
[root@localhost ~]# pip install httpbin
[root@localhost ~]# pip install guicorn
#启动httpbin
[root@localhost ~]# gunicorn -b :8000 httpbin:app
[2017-07-11 16:25:29 +0000] [21088] [INFO] Starting gunicorn 19.7.1
[2017-07-11 16:25:29 +0000] [21088] [INFO] Listening at: http://0.0.0.0:8000 (21088)
[2017-07-11 16:25:29 +0000] [21088] [INFO] Using worker: sync
[2017-07-11 16:25:29 +0000] [21093] [INFO] Booting worker with pid: 21093
#访问httpbin主页面
[root@localhost ~]# lynx localhost:8000

 

接口列表

EndpointDescirption
/This page.
/ipReturns Origin IP.
/user-agentReturns user-agent.
/headersReturns header dict.
/getReturns GET data.
/postReturns POST data.
/patchReturns PATCH data.
/putReturns PUT data.
/deleteReturns DELETE data
/gzipReturns gzip-encoded data.
/deflateReturns deflate-encoded data.
/status/:codeReturns given HTTP Status code.
/response-headersReturns given response headers.
/redirect/:n302 Redirects n times.
/redirect-to?url=foo302 Redirects to the foo URL.
/relative-redirect/:n302 Relative redirects n times.
/cookiesReturns cookie data.
/cookies/set?name=valueSets one or more simple cookies.
/cookies/delete?nameDeletes one or more simple cookies.
/basic-auth/:user/:passwdChallenges HTTPBasic Auth.
/hidden-basic-auth/:user/:passwd404'd BasicAuth.
/digest-auth/:qop/:user/:passwdChallenges HTTP Digest Auth.
/stream/:nStreams n – 100 lines.
/delay/:nDelays responding for n – 10 seconds.
/dripDrips data over a duration after an optional initial delay, then (optionally) returns with the given status code.
/range/:nStreams n bytes, and allows specifying a Range header to select a subset of the data. Accepts a chunk_size and request duration parameter.
/htmlRenders an HTML Page.
/robots.txtReturns some robots.txt rules.
/denyDenied by robots.txt file.
/cacheReturns 200 unless an If-Modified-Since or If-None-Match header is provided, when it returns a 304.
/cache/:nSets a Cache-Control header for n seconds.
/bytes/:nGenerates n random bytes of binary data, accepts optional seed integer parameter.
/stream-bytes/:nStreams n random bytes of binary data, accepts optional seed and chunk_size integer parameters.
/links/:nReturns page containing n HTML links.
/forms/postHTML form that submits to /post
/xmlReturns some XML
/encoding/utf8Returns page containing UTF-8 data.

例子

[root@localhost ~]# curl http://httpbin.org/ip
{
  "origin": "218.189.127.78"
}
[root@localhost ~]# curl http://httpbin.org/user-agent
{
  "user-agent": "curl/7.29.0"
}
[root@localhost ~]# curl https://httpbin.org/get?show_env=1
{
  "args": {
    "show_env": "1"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Connect-Time": "0", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "Total-Route-Time": "0", 
    "User-Agent": "curl/7.29.0", 
    "Via": "1.1 vegur", 
    "X-Forwarded-For": "218.189.127.78", 
    "X-Forwarded-Port": "443", 
    "X-Forwarded-Proto": "https", 
    "X-Request-Id": "392e0fda-5f1b-4cc8-8131-77967bfee9db", 
    "X-Request-Start": "1499761771703"
  }, 
  "origin": "218.189.127.78", 
  "url": "https://httpbin.org/get?show_env=1"
}
[root@localhost ~]# curl -I http://httpbin.org/status/418
HTTP/1.1 418 I'M A TEAPOT
Connection: keep-alive
Server: meinheld/0.6.1
Date: Tue, 11 Jul 2017 08:29:40 GMT
X-Processed-Time: 0.000515937805176
Access-Control-Allow-Origin: *
X-More-Info: http://tools.ietf.org/html/rfc2324
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
Content-Length: 135
Via: 1.1 vegur

[root@localhost ~]# curl http://httpbin.org/get
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.29.0"
  }, 
  "origin": "218.189.127.78", 
  "url": "http://httpbin.org/get"
}

参考

1、 kennethreitz/httpbin

2、guicorn是什么

转载链接:https://www.jianshu.com/p/00db00cd287d
 

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值