通过 postman ,我将数据发布到特定的 URL,如 site.com/read_request.php
。
当我选择原始数据 application/xml 时,它会按预期提供输出,但是对于 application/json,它会给我 403
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /tomy/url
on this server.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at ......com Port 80</address>
</body></html>
我尝试添加
header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");
但运气不好,从服务器端我们可以只阻止 application/json 请求吗? 如果是如何调试?
最佳答案
在服务器上您需要访问的文件夹中添加一个 .htaccess 文件。
在该 .htaccess 文件中添加:
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
这确保您可以向其发布内容。 但其他人也可以,所以要小心!
关于php - application/json 所有请求都转到 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45543219/