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

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab