Recently I have upgraded my rest server to Zf2 Apigility, which the content negotiation settings are as follows,
'zf-content-negotiation' => array(
'controllers' => array(
'CloudSchoolBusFileApi\\V1\\Rest\\FileReceiver\\Controller' => 'Json',
),
'accept_whitelist' => array(
'CloudSchoolBusFileApi\\V1\\Rest\\FileReceiver\\Controller' => array(
0 => 'application/vnd.cloud-school-bus-file-api.v1+json',
1 => 'application/json',
),
),
'content_type_whitelist' => array(
'CloudSchoolBusFileApi\\V1\\Rest\\FileReceiver\\Controller' => array(
0 => 'application/vnd.cloud-school-bus-file-api.v1+json',
1 => 'application/json',
2 => 'multipart/form-data',
),
),
The problem is that my client(mobie app) has already deployed and the they send post requests with no Accept field setting in the http header. so I always got following 406 error from the server,
[Response] => Array
(
[statusCode] => 406
[content] => {"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Not Acceptable","status":406,"detail":"Cannot honor Accept type specified"}
)
So anyone has an idea of how to let the server accept such request from client with no Accept in header?
You could write a listener in which you check the
Accept
header of the incoming request. If noAccept
header is set you can add anAccept
header with a default value; for exampleapplication/json
.So something like:
Better would of course be to update your client.