Commit 14758092 authored by liupei's avatar liupei

修复http返回失败问题

parent dd0f643a
...@@ -31,6 +31,7 @@ func NewResponse(httpResponse http.Response, reqErr error) Response { ...@@ -31,6 +31,7 @@ func NewResponse(httpResponse http.Response, reqErr error) Response {
// init 解析钉钉返回 // init 解析钉钉返回
func (res *Response) init() { func (res *Response) init() {
body, err := ioutil.ReadAll(res.httpResponse.Body) body, err := ioutil.ReadAll(res.httpResponse.Body)
defer res.httpResponse.Body.Close()
if err != nil { if err != nil {
res.success = false res.success = false
res.httpErr = err.Error() res.httpErr = err.Error()
...@@ -38,7 +39,7 @@ func (res *Response) init() { ...@@ -38,7 +39,7 @@ func (res *Response) init() {
} }
res.httpBody = string(body) res.httpBody = string(body)
res.errCode = gjson.Get(res.httpBody, "errcode").Int() res.errCode = gjson.Get(res.httpBody, "errcode").Int()
if (res.httpCode >= 200 && res.httpCode < 400) && res.errCode == 0 { if (res.httpResponse.StatusCode >= 200 && res.httpResponse.StatusCode < 400) && res.errCode == 0 {
res.success = true res.success = true
} else { } else {
res.success = false res.success = false
...@@ -53,7 +54,7 @@ func (res *Response) IsSuccess() bool { ...@@ -53,7 +54,7 @@ func (res *Response) IsSuccess() bool {
// GetHttpCode 返回httpCode // GetHttpCode 返回httpCode
func (res *Response) GetHttpCode() int { func (res *Response) GetHttpCode() int {
return res.httpCode return res.httpResponse.StatusCode
} }
// GetBodyData 返回钉钉返回数据 // GetBodyData 返回钉钉返回数据
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment