我尝试使用HTTP GET方法:
curl http://localhost:8888/_ah/api/birra/v1/beer
它将当前列表归还给我,这是正常的和预期的:
{
"items" : [ {
"id" : "1",
"beerName" : "Bud"
}, {
"id" : "2",
"beerName" : "Steve"
}, {
"id" : "3",
"beerName" : "Ankur"
} ]
}
但是当我这样做HTTP POST时:
curl -X POST -H "Content-Type: application/json" -H "Accept:application/json" -d "{\"beerName\": \"asdf\"}" http://localhost:8888/_ah/api/birra/v1/beer
它给我的错误是:
{
"error" : {
"message" : "javax.jdo.JDOFatalInternalException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null.\nNestedThrowables:\norg.datanucleus.exceptions.NucleusException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null.",
"code" : 503,
"errors" : [ {
"domain" : "global",
"reason" : "backendError",
"message" : "javax.jdo.JDOFatalInternalException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null.\nNestedThrowables:\norg.datanucleus.exceptions.NucleusException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null."
} ]
}
}
我目前正在处理以下提供的Google Cloud Endpoints示例: Cloud Endpoint by Google Developers
我正在使用Eclipse IDE和在Jetty上运行的服务器localhost。
任何解决方案?
答案 0 :(得分:3)
使用双引号而不是单引号。从Windows运行时会发生此类错误。这就是为什么它说couldn't resolve host
。
curl -H "Content-Type: application/json" -d "{\"beerName\": \"bud\"}" http://localhost:8888/_ah/api/birra/v1/beer