[英]Apigility - Invalid content type specified
我正在嘗試將登錄憑據發布到功能登錄API:
$response = ClientStatic::post(
'http://www.example.com/api/login',
array('email' => 'test@eample.com','password' => 'test'),
array('Accept' => 'application/json')
);
這將返回錯誤:
無法接受指定的接受類型
據我所知, application/json
已在配置中列入白名單:
有任何想法嗎?
我的適應性配置:
<?php
return array(
'controllers' => array(
'factories' => array(
'Api\\V1\\Rpc\\Login\\Controller' => 'Api\\V1\\Rpc\\Login\\LoginControllerFactory',
),
),
'router' => array(
'routes' => array(
'api.rpc.login' => array(
'type' => 'Segment',
'options' => array(
'route' => '/api/login',
'defaults' => array(
'controller' => 'Api\\V1\\Rpc\\Login\\Controller',
'action' => 'login',
),
),
),
),
),
'zf-versioning' => array(
'uri' => array(
0 => 'api.rpc.login',
),
),
'zf-rpc' => array(
'Api\\V1\\Rpc\\Login\\Controller' => array(
'service_name' => 'Login',
'http_methods' => array(
0 => 'POST',
1 => 'GET',
),
'route_name' => 'api.rpc.login',
),
),
'zf-content-negotiation' => array(
'controllers' => array(
'Api\\V1\\Rpc\\Login\\Controller' => 'Json',
),
'accept_whitelist' => array(
'Api\\V1\\Rpc\\Login\\Controller' => array(
0 => 'application/vnd.api.v1+json',
1 => 'application/json',
2 => 'application/*+json',
),
),
'content_type_whitelist' => array(
'Api\\V1\\Rpc\\Login\\Controller' => array(
0 => 'application/vnd.api.v1+json',
1 => 'application/json',
),
),
),
'zf-content-validation' => array(
'Api\\V1\\Rpc\\Login\\Controller' => array(
'input_filter' => 'Api\\V1\\Rpc\\Login\\Validator',
),
),
'input_filter_specs' => array(
'Api\\V1\\Rpc\\Login\\Validator' => array(
0 => array(
'required' => true,
'validators' => array(
0 => array(
'name' => 'Zend\\Validator\\EmailAddress',
'options' => array(
'useDomainCheck' => true,
),
),
),
'filters' => array(),
'name' => 'email',
'description' => 'Email address',
'error_message' => 'Email address error',
),
1 => array(
'required' => true,
'validators' => array(),
'filters' => array(),
'name' => 'password',
'description' => 'Password required',
'error_message' => 'Password error',
),
),
),
'zf-mvc-auth' => array(
'authorization' => array(
'Api\\V1\\Rpc\\Login\\Controller' => array(
'actions' => array(
'Login' => array(
'GET' => false,
'POST' => false,
'PUT' => false,
'PATCH' => false,
'DELETE' => false,
),
),
),
),
),
);
您確實在zf-content-negotiation
配置中設置了一個controllers
鍵,並指向一個Json
選擇器。 但是未配置此選擇器。 這可能是您問題的一部分。 您還可以在zfcampus / zf-content-negotiation文檔中閱讀有關此內容的信息 。 您應該添加類似以下內容:
'selectors' => array(
'Json' => array(
'ZF\ContentNegotiation\JsonModel' => array(
'application/json',
'application/*+json',
),
),
),
如果這樣不能解決您的問題,請添加評論...
您可以添加一個新的selector
下,在管理用戶界面[main menu] -> Content Negotiation -> [button] New selector
然后在其中添加/刪除/編輯選擇器,例如,向其中添加ViewModel
。
服務的內容協商設置位於[side menu] -> Foo API -> Bar service -> Content Negotiation
。 可以從內容列表中選擇服務的Content Negotiation Selector
,並可以編輯媒體類型
(刪除似乎有問題,無法正常工作-但無論如何,也可以在關鍵zf-content-negotiation
中的module.config.php
中完成module.config.php
)。
在這種情況下,解決方案是運行composer.phar更新來解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.