通过邮递员,我将数据发布到site.com/read_request.php
等特定网址。
当我选择原始数据应用程序/ 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: *");
但没有运气,从服务器端我们可以只阻止应用程序/ json请求吗? 如果是,如何调试?
答案 0 :(得分:1)
在您需要在服务器上访问的文件夹中添加.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"
这可以确保您可以发布内容。 但其他人也可以,所以要小心!