簡體   English   中英

使用curl將數據發布到localhost的HTTP Post方法失敗

[英]HTTP Post method using curl to post data to localhost failed

我正在嘗試使用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開發人員提供的Google Cloud Endpoints示例: Cloud Endpoint

我正在使用Eclipse IDE和在Jetty上運行的服務器localhost。

有解決方案嗎

使用雙引號而不是單引號。 從Windows運行時會發生此類錯誤。 這就是它說couldn't resolve host

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM