服务器直接 curl 命令是可以的,单独把 curl 拿出来也可以,但如下却没有返回
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 ,但这应该不是版本问题吧
求教大佬
1
AoEiuV020CN 2023-04-23 14:25:57 +08:00
不懂 go ,但这情况我一般会抓包对比看看先,
|
2
bruce0 2023-04-23 15:10:27 +08:00
这个请求过程是异步的吗,如果是 会不会是 数据还没返回 测试程序就退出了
|
4
yrj 2023-04-24 03:32:19 +08:00
我感觉你这样提问,没用过 gf 的!就只能盲猜了。建议你跟进去看看里面他 curl 的过程,是不是某个方法在某一步做了啥
|
5
chenall 2023-04-24 08:05:10 +08:00 via Android
thelog
出了 if 语句就失效了 先定义一下再使用。 |
6
fenglangjuxu 2023-04-24 09:22:21 +08:00
吧 defer 去掉试试
虽然看起来 defer 用的没问题 |
7
chenall 2023-04-24 15:22:49 +08:00
我 #5 用手机端看错了.
看日志好像是返回异常了? |
8
kestrelBright OP @AoEiuV020CN 大佬看不大懂抓包结果。。
这是抓的客户端,请求两次偶尔第一次能成功,第二次一定失败 然后服务端的 服务端也可能收得到第二次的请求,但请求数据不完整 blob:https://imgur.com/3bff1e4b-0f71-45f6-9e27-822cd443f4e9 |
9
kestrelBright OP |
10
AoEiuV020CN 2023-04-25 16:18:37 +08:00
@kestrelBright #8 你这抓的太底层了, 我意思是抓 http 层的包,对比两个 http request 的区别,你这图里啥也没有,
|
11
kestrelBright OP @AoEiuV020CN 没区别 除了报文大小
第一次 ``` POST /GDB HTTP/1.1 Host: 192.168.1.22:1799 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0 Content-Length: 777 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: Accept-Language: zh-CN,zh;q=0.9 Cache-Control: max-age=0 Connection: close Content-Type: application/json Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip [Full request URI: http://192.168.1.22:1799/GDB] [HTTP request 1/1] File Data: 777 bytes ``` 第二次 ``` POST /GDB HTTP/1.1 Host: 192.168.1.22:1799 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0 Content-Length: 1011 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: Accept-Language: zh-CN,zh;q=0.9 Cache-Control: max-age=0 Connection: close Content-Type: application/json Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip ``` |
12
kestrelBright OP md 就是网络问题
|