V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kestrelBright
V2EX  ›  程序员

求助 golang 大佬一个 curl 问题

  •  
  •   kestrelBright · 2023-04-23 13:32:21 +08:00 · 638 次点击
    这是一个创建于 370 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用的 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 ,但这应该不是版本问题吧

    求大佬指教

    lhbc
        1
    lhbc  
       2023-04-23 14:01:51 +08:00 via Android
    是我水平太差了吗?
    我看不懂问什么
    kestrelBright
        2
    kestrelBright  
    OP
       2023-04-23 14:03:15 +08:00
    @lhbc curl 请求没有返回
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2906 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:01 · PVG 17:01 · LAX 02:01 · JFK 05:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.