Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Post method using curl to post data to localhost failed

I'm trying to use HTTP GET method using:

curl http://localhost:8888/_ah/api/birra/v1/beer

it's returning me the current list like which is normal and expected:

{
  "items" : [ {
    "id" : "1",
    "beerName" : "Bud"
  }, {
    "id" : "2",
    "beerName" : "Steve"
  }, {
    "id" : "3",
    "beerName" : "Ankur"
  } ]
}

But when i'm doing HTTP POST like this:

curl -X POST -H "Content-Type: application/json" -H "Accept:application/json" -d "{\"beerName\": \"asdf\"}" http://localhost:8888/_ah/api/birra/v1/beer

it's giving me error as:

{
  "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."
    } ]
  }
}

I'm currently working on Google Cloud Endpoints sample provided on: Cloud Endpoint by Google Developers

I'm using Eclipse IDE with server localhost running on Jetty.

Any solutions?

like image 343
ankur Avatar asked Oct 21 '25 04:10

ankur


1 Answers

Use double quote instead of single. This type of errors occur when you are running from windows. That's why it says couldn't resolve host.

curl  -H "Content-Type: application/json" -d "{\"beerName\": \"bud\"}" http://localhost:8888/_ah/api/birra/v1/beer
like image 56
Sabuj Hassan Avatar answered Oct 22 '25 17:10

Sabuj Hassan