【问题标题】:500 internal server error for Curl command for POST method(for JSON ) of restful web service using Go500 内部服务器错误,用于使用 Go 的 restful Web 服务的 POST 方法(用于 JSON)的 Curl 命令
【发布时间】:2014-04-22 00:58:49
【问题描述】:

有一个名为 countries.go 的文件 它导入包 github.com/ant0ine/go-json-rest/rest。

来自

的参考代码

https://gowalker.org/github.com/ant0ine/go-json-rest#countries

国家版块:POST DELETE 等演示

当我尝试使用命令时 curl -i -d '{"Code":"FR","Name":"France"}' http_URL

它给了

{ “错误”:“无效字符 '\'' 正在寻找值的开头” }

我已经使用了上面给出的包。似乎 request.go 中的方法作为 DecodeJsonPayload() 实现了 JSON 的 unmarshal() 有内部服务器错误。

我无法纠正。感谢您的帮助

【问题讨论】:

  • 也许你需要做一些字符串转义字符..

标签: json rest curl go


【解决方案1】:

我设法在 Windows 上使用 curl 复制了您的问题。

请改用以下 curl 命令:

curl -i -d "{\"Code\":\"FR\",\"Name\":\"France\"}" http_URL

一个相关的 SO 问题:How to send double quote in -d parameter for curl.exe?

【讨论】:

  • 这行得通,但我想知道 Unmarshal 方法是否不能解决这个问题??
  • 不,不能。因为 curl 会将'{Code:FR,Name:France}'(包括撇号)发送到 Go 服务器。那是损坏的 JSON,而 json 包需要有效的 json 数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-28
  • 1970-01-01
  • 2016-10-13
  • 1970-01-01
  • 2018-06-04
  • 2018-01-06
  • 1970-01-01
相关资源
最近更新 更多