![](/img/trans.png)
[英]Consuming a RESTful WebService passing a JSON object as request body
[英]Consuming & exposing a REST service and passing JSON body
我正在使用 Apache Camel 和 XML DSL 來使用和公開 REST 服務。 我有一個請求正文{"name":"your name","phonenumber":"111-111"}
我成功地能夠直接發送這個 json 請求正文並從消費端點 url 獲得成功的響應。 而當我通過暴露的 URL go 時,我得到以下異常。
org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking
<!--Consumed URL--> with statusCode: 400 /n responseBody:
{"timestamp":"2020-04-07T06:15:41.302+0000","status":400,"error":"Bad Request",
"message":"Required request body is missing: public boolean
com.agcs.cids.BookingRestController.createBooking(org.bson.Document...)","path":"-----"}
在我打電話給 URL 之前,我什至能夠成功打印正文。 請在下面完善我的代碼:
<log loggingLevel="TRACE" message="Request from source: Body: ${body}" />
<log loggingLevel="TRACE" message="Request from source: Header: ${headers}" />
<to uri="restlet:<--Consumed URL-->?restletMethod=POST" />
我猜你的代碼試圖要么 -
{"name":"your name","phonenumber":"111-111"}
JSON 正文的POST
請求。 在這種情況下,您可能想重新訪問您的代碼並驗證您是否正確設置了正文,例如<setBody>
在<to>
和<from>
標記中正確使用。JSON
主體的 URL 發送POST
請求。 您是否嘗試將"Accept", "application/json"
添加為 header?<from>
和<to>
地址(您提到了“Consumed URL”,在<to>
端點的情況下,它在語義上應該是“Consuming URL”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.