[英]Luracast Restler is sending 'text/html' instead of 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会自动引发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.