donglu9978 2013-02-08 17:53
浏览 1017
已采纳

Go-http.Post方法返回400 Bad Request,而http.Get似乎有效

With the following code:

//fpCode and fpParams are strings
ingestionBody := strings.NewReader(fpCode+fpParams)
resp, err := http.Post("http://192.168.1.151:8080/ingest?", "text/plain", ingestionBody)

I'm getting the error message: "HTTP/1.1 POST /ingest" - 400 Bad Request

I don't know if I'm not using the Post method right (even when in this answer, they seem to use it in a similar way. Is the only example that I was able to find, unfortunatelly Go documentation lacks of examples), the problem is with the second parameter, which should be something different (but I also tried "text/*") or there is something important that I'm missing.

  • 写回答

2条回答 默认 最新

  • dsa4d4789789 2013-02-11 02:11
    关注

    Perhpas you can try http.PostForm:

    form := url.Values{}
    form.Add("field1", a)
    form.Add("field2", b)
    http.PostForm("http://192.168.1.151:8080/ingest", form)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料