作者:手机用户2502905117 | 来源:互联网 | 2022-12-04 18:29
我已经在vps中构建了基本授权和cors.
curl -X OPTIONS -i http://111.111.111.111
HTTP/1.1 200 OK
Date: Sat, 15 Sep 2018 08:07:37 GMT
Server: Apache/2.4.6 (CentOS)
Access-Control-Allow-Origin: http://127.0.0.1
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With
Allow: OPTIONS,GET,HEAD,POST,TRACE
Content-Length: 0
Content-Type: httpd/unix-directory
curl -u xxxx:xxxx -i http://111.111.111.111/remote.php
HTTP/1.1 200 OK
Date: Sat, 15 Sep 2018 08:08:07 GMT
Server: Apache/2.4.6 (CentOS)
Access-Control-Allow-Origin: http://127.0.0.1
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With
Last-Modified: Sat, 15 Sep 2018 07:54:13 GMT
ETag: "24-575e43f02c324"
Accept-Ranges: bytes
Content-Length: 36
您可以看到授权和cors处于良好状态.
我的本地目录中的test-ajax-cors.html /var/www/html
.
何时第一次调用remote.php,remote.php的resposne中没有内容.
第一个请求可能是CORS-preflight请求,浏览器发送OPTIONS请求而没有任何Authorization标头,在我的情况下,服务器向浏览器发送200状态代码,这意味着一切都处于良好状态.
remote.php响应的内容第二次调用remote.php时的响应.
如何使第二个响应中的内容显示为 127.0.0.1/test-ajax-cors.html
.
感谢Sally CJ的通知.
yum install mod_php
systemctl restart httpd
输入127.0.0.1/test-ajax-cors.html
,单击show content
.
1.alert错误信息
2. remote.php
被召唤两次,所有的反应remote.php
都是一样的.
{"name","myname"}
内容是我所期望的,为什么不能在网页中显示 127.0.0.1\test-ajax-cors.html
,这导致警报错误信息?