簡體   English   中英

Luracast Restler JSON格式驗證

[英]Luracast Restler JSON format validation

我想知道Restler是否可以處理JSON請求格式的驗證?

例如,我有這個JSON請求:

{ "id" : 1, "party_id" : , "description" : "say it here" }

party_id的值應無效。 有什么見解嗎? 謝謝。

Restler 2.0.5中的JSON驗證

Restler 2.0.5版開始,當請求中的JSON主體格式錯誤時,restler會自動引發HTTP 400狀態並顯示有意義的錯誤消息。

例如

curl -X POST http://restler2.dev/examples/_006_crud/index.php/author -H "Content-Type: application/json" -d '{"name": "Another", "email": "another@email.com'

退貨

{
  "error": {
    "code": 400,
    "message": "Bad Request: Error parsing JSON, malformed JSON"
  }
}

需要PHP 5.3以上

更新

Restler 2.0.6添加了對舊版本PHP 5的錯誤支持

因此,使用PHP 5.2.17的help.luracast.com/restler/examples將為cURL返回以下響應

curl -X POST http://help.luracast.com/restler/examples/_006_crud/index.php/authr -H "Content-Type: application/json" -d '{"name": "Another", "email": "another@email.com",}'

{
  "error": {
    "code": 400,
    "message": "Bad Request: Error parsing JSON"
  }
}

暫無
暫無

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

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