gpt4 book ai didi

cakephp - cakephp 3.8.13处理未经授权的请求,以JSON响应

转载 作者:行者123 更新时间:2023-12-03 07:51:48 25 4
gpt4 key购买 nike

我已经在CakePHP应用程序中实现了https://github.com/ADmad/cakephp-jwt-auth。我的问题是,每当有未经授权的请求时,它都会用HTML响应。

    <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>
但是根据本教程 https://www.bravo-kernel.com/2015/04/how-to-add-jwt-authentication-to-a-cakephp-3-rest-api/,它将使用JSON进行响应。本教程的示例响应为
{
"success": false,
"data": {
"message": "You are not authorized to access that location.",
"url": "\/api\/cocktails.json",
"code": 401
}
}
这是我的路由器
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中的未经授权的响应。谢谢。

最佳答案

您可以尝试使用 Accept发送以下HTTP请求吗:application/json header

关于cakephp - cakephp 3.8.13处理未经授权的请求,以JSON响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64244330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com