求助 golang 大佬一个 curl 问题

2023-04-23 13:32:21 +08:00
 kestrelBright

使用的 goframe 框架

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-----"}

但如果单独拿出来请求是可以的,全部都正常返回

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)
}	

最近迁移了服务器,go 版本由 1.16 升级到 1.19 ,但这应该不是版本问题吧

求大佬指教

652 次点击
所在节点    程序员
2 条回复
lhbc
2023-04-23 14:01:51 +08:00
是我水平太差了吗?
我看不懂问什么
kestrelBright
2023-04-23 14:03:15 +08:00
@lhbc curl 请求没有返回

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/934758

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX