httpbin http 请求调试利器

很多时候我们都需要模拟数据请求,简单的场景:我们需要调试一个上传 JS 的插件,那么肯定要部署后端,httpbin 的出现,使我们大大节省了时间和繁琐。

httpbin是什么

httpbin是一个HTTP Request & Response Service,你可以向他发送请求,然后他会按照指定的规则将你的请求返回。这个类似于echo服务器,但是功能又比它要更强大一些。 httpbin支持HTTP/HTTPS,支持所有的HTTP动词,能模拟302跳转乃至302跳转的次数,还可以返回一个HTML文件或一个XML文件或一个图片文件(还支持指定返回图片的格式)。实在是请求调试中居家必备的良器!

httpbin怎么用

httpbin的使用方法非常简单,你只需要把请求的地址修改为httpbin.org即可。 比如:

获取请求中的user-agent

请求:

curl http://httpbin.org/user-agent

返回:

{"user-agent": "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3"}

查看自己的GET请求

请求:

curl http://httpbin.org/get

返回:

{
   "args": {},
   "headers": {
      "Accept": "*/*",
      "Connection": "close",
      "Content-Length": "",
      "Content-Type": "",
      "Host": "httpbin.org",
      "User-Agent": "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3"
   },
   "origin": "24.127.96.129",
   "url": "http://httpbin.org/get"
}

更多的用法可以参考官方的主页: https://httpbin.org/

如何部署在内网

考虑到httpbin部署在国外,加上业务调试的时候不想跟外部的服务器交互,httpbin也可以采用自己部署的方式。

从Pypi安装并使用

pip install httpbin gunicorn
gunicorn httpbin:app

从源码安装

git clone https://github.com/Runscope/httpbin.git
pip install -e httpbin
python -m httpbin.core [--port=PORT] [--host=HOST]

猜你喜欢

转载自blog.csdn.net/myarche/article/details/116781041