cakephp 3.8.13以JSON处理未经授权的请求、响应
我已经在CakePHP应用程序中实现了。我的问题是,每当有未经授权的请求时,它就会用HTML响应cakephp 3.8.13以JSON处理未经授权的请求、响应,cakephp,error-handling,unauthorized,cakephp-3.8,Cakephp,Error Handling,Unauthorized,Cakephp 3.8,我已经在CakePHP应用程序中实现了。我的问题是,每当有未经授权的请求时,它就会用HTML响应 <html> <head> <meta charset="utf-8"/> <title> CakePHP: the rapid development php framework: Error </ti
<html>
<head>
<meta charset="utf-8"/>
<title>
CakePHP: the rapid development php framework:
Error </title>
<link href="/favicon.ico" type="image/x-icon" rel="icon"/>
<link href="/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
<link rel="stylesheet" href="/css/cake.generic.css"/>
</head>
<body>
<div id="container">
<div id="header">
<h1>
<a href="https://cakephp.org">CakePHP: the rapid development php framework</a>
</h1>
</div>
<div id="content">
<h2>Unauthorized</h2>
<p class="error">
<strong>Error: </strong>
An Internal Error Has Occurred.
</p>
</div>
</div>
</body>
</html>
这是我的路由器
Router::prefix('api', function ($routes) {
$routes->extensions(['json', 'xml']);
Router::connect('/api/check', ['_method' => 'GET','controller' => 'EmailNotification', 'action' => 'check', 'prefix' => 'api']);
$routes->fallbacks('DashedRoute');
});
我该怎么办?我想要JSON中未经授权的响应。谢谢。您可以尝试使用接受:应用程序/json头发送您的http请求吗?您还可以发布方法检查()吗?我正在使用邮递员。发送请求没有问题。
Router::prefix('api', function ($routes) {
$routes->extensions(['json', 'xml']);
Router::connect('/api/check', ['_method' => 'GET','controller' => 'EmailNotification', 'action' => 'check', 'prefix' => 'api']);
$routes->fallbacks('DashedRoute');
});