shared.Common.LogReceiveapi(g.Map{
"url": url,
"con": res,
"status": "----now start push-----",
}, logpath+"/returnData")
// 推送地址
//content := g.Client().ContentJson().PostContent(url, res)
result, err := g.Client().ContentJson().Post(url, res)
if err != nil {
thelog := g.Map{
"dump": result.Raw(),
"error": err,
"status": "----push error-----",
}
// 记录返回的数据
shared.Common.LogReceiveapi(thelog, logpath+"/returnData")
return errors.New("推送失败: " + err.Error())
}
defer result.Close()
content := result.ReadAllString()
thelog := g.Map{
"dump": result.RawDump,
"res": content,
"status": "----end push-----",
}
// 记录返回的数据
shared.Common.LogReceiveapi(thelog, logpath+"/returnData")
日志
2023-04-23 11:11:38.785 {"con":{"name":"xxx","list":[{"name":"xx","remark":"xxx","status":""}]},"status":"----now start push-----","url":"http://xxx"}
2023-04-23 11:12:38.802 {"dump":"+---------------------------------------------+\n| REQUEST |\n+---------------------------------------------+\nPOST /GDB HTTP/1.1\r\nHost: 192.168.88.229:1799\r\nUser-Agent: GoFrameHTTPClient v1.16.6\r\nContent-Length: 1296\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n\n\n\n","error":{"Op":"Post","URL":"http://xxx","Err":{}},"status":"----push error-----"}
日志打印请求只能看到 request ,没有 response
如果单独拿出来放到某个 func 里能够正常返回,如这样
func (a *bankInsideApi) TestCurl(r *ghttp.Request) {
g.Dump("--000---")
content := g.Client().ContentJson().PostContent("http://xxx", g.Map{})
g.Dump("--111--", content)
content = g.Client().ContentJson().PostContent("http://xxx", g.Map{
"name": "xxx",
"list": g.Array{
g.Map{
"name": "test",
"remark": "xxx",
"status": "",
},
},
})
g.Dump("--22222--", content)
}
能够看到
--000---
--111--{"code":"0","message":"xxx","timestamp":1682219117811}
--22222--{"code":"1","errorCode":"xxx","message":"xxx","errorMsg":"xxx","timestamp":1682219118092}
使用的 goframe 框架, 最近迁移了服务器,go 版本由 1.16 升级到 1.19 ,但这应该不是版本问题吧
求教大佬