500 internal server error for Curl command for POST method(for JSON ) of restful web service using Go

huangapple go评论98阅读模式
英文:

500 internal server error for Curl command for POST method(for JSON ) of restful web service using Go

问题

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

参考代码来自https://gowalker.org/github.com/ant0ine/go-json-rest#countries。

Countries部分:演示POST DELETE等操作。

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

它返回:

{
"Error": "invalid character '\' looking for beginning of value"
}

我已经使用了上述给出的包。似乎请求中的request.go文件中的DecodeJsonPayload()方法,在实现JSON的unmarshal()时出现了内部服务器错误。

我无法纠正这个问题。希望能得到帮助。

英文:

There is a file named countries.go
It imports package github.com/ant0ine/go-json-rest/rest.

referred code from

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

Countries section:Demo of POST DELETE etc

When i try to use command
curl -i -d '{"Code":"FR","Name":"France"}' http_URL

It gives

{
"Error": "invalid character '\'' looking for beginning of value"
}

I have used the package given above .It seems the method in the request.go given as DecodeJsonPayload() ,which implements unmarshal() for JSON , have internal server error.

I am unable to correct that.Help appreciated

答案1

得分: 1

我成功地在Windows上使用curl复制了你的问题。

请使用以下curl命令代替:

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

相关的SO问题:https://stackoverflow.com/questions/4514199/how-to-send-double-quote-in-d-parameter-for-curl-exe

英文:

I managed to duplicate your problem with curl on Windows.

Use the following curl command instead:

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

A related SO question: https://stackoverflow.com/questions/4514199/how-to-send-double-quote-in-d-parameter-for-curl-exe

huangapple
  • 本文由 发表于 2014年4月22日 08:58:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/23208566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定