Think Deep,Work Lean

关于httpbin讲解

Posted on By zack

关于httpbin

在所有需要做HTTP请求的开发过程中,总有一个这样的痛点:我发出去的请求到底是什么样子的?特别是在一些需要签名和认证的场合,服务器只会冷冰冰的返回一个40x错误,你无从得知错误的具体详情。此时可借助于httpbin来查看自己的具体请求:

~ curl http://httpbin.org/ip
{
  "origin": "139.198.254.11"
}

~ curl http://httpbin.org/user-agent
{
  "user-agent": "curl/7.64.1"
}

~ curl http://httpbin.org/get
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.64.1",
    "X-Amzn-Trace-Id": "Root=1-6030e123-6f99c1934751f48c79af41fc"
  },
  "origin": "139.198.254.11",
  "url": "http://httpbin.org/get"
}

~ curl http://httpbin.org/headers
{
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.64.1",
    "X-Amzn-Trace-Id": "Root=1-6030e1f7-3648112772df86665d5409f0"
  }
}

自己部署httpbin

kubectl create deploy httpbin --image zackzhangkai/httpbin --port 80
kubectl expose deploy httpbin --port 8080 --target-port 80

https://github.com/postmanlabs/httpbin/blob/master/httpbin/core.py#L240