我是使用Zend Framework 2和Zend Framework的Apigility构建RESTful API的.为了测试,我使用chrome扩展Postman REST-Client.
通过发送表单数据没有问题,我可以毫无问题地执行GET请求和POST请求.
但是当我尝试执行PUT,PATCH或DELETE请求时,我收到以下错误:
{
"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title":"Unsupported Media Type",
"status":415,
"detail":"Invalid content-type specified"
}
Run Code Online (Sandbox Code Playgroud)
在Rest-Service-Config of Apigility中接受白名单:
application/vnd.timber-ms.v1+json, application/hal+json, application/json
Run Code Online (Sandbox Code Playgroud)
内容类型白名单:
application/vnd.timber-ms.v1+json, application/json
Run Code Online (Sandbox Code Playgroud)
响应的内容类型是 application/problem+json
我该怎么做才能解决这个问题并成功完成PUT/PATCH请求?这是Postman或Apigility的问题吗?
我正在使用Apigility和Zend Framework 2构建REST API.在这个API中,我有一个代码连接的REST服务,当我尝试删除一个实体时,我遇到了一个奇怪的行为.我使用我的TableGateway对象的delete方法删除传递到"Resource"文件的delete方法的数据:
public function delete($id)
{
//GetTable returns a TableGateway instance
$this->getTable('order')->delete(array('id' => $id));
return array("status" => "deleted", "id" => $id);
}
Run Code Online (Sandbox Code Playgroud)
我通过使用Postman REST客户端测试了这个函数并获得了响应:
{
"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title":"Unprocessable Entity",
"status":422,
"detail":"Unable to delete entity."
}
Run Code Online (Sandbox Code Playgroud)
但是,当我检查mysql数据库时,正确删除了有问题的实体.没有出现错误的迹象.
返回这种错误的原因是什么?
更新:代码到达TableGateway删除函数调用后的行.这意味着响应可能是在调用函数之后构建的,并且忽略了返回的返回值.