net/http 包请求一个 URL 地址,返回状态码是非 200,比如 400,如何获取响应体的内容呢?
测试结果:
- 使用 postman 、Python requests 库获取内容
{
"errcode": 4023,
"errmsg": "认证失败"
}
- 使用 go net/http 包 获取内容
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
net/http 包是否状态码 200 才读响应体的内容呢?