如果存在Access-Control-Allow-Origin:*,为什么Ajax请求以错误403响应

时间:2019-05-24 03:27:39

标签: javascript apache solr cors

我有一个Apache HTTP服务器作为solr服务器的代理。 我正在尝试使用Ajax请求进行solr。 但是我得到了错误:

$ conda list --show-channel-urls

...

sympy                     1.3                      py37_0    defaults
tblib                     1.3.2                    py37_0    defaults
tensorflow-gpu            1.9.0                hf154084_0    file:///home/billtubbs/pkgs-for-anaconda
terminado                 0.8.1                    py37_1    defaults
testpath                  0.4.2                    py37_0    defaults

如果我在浏览器中直接访问该地址,它将起作用:

Request URL: http://localhost/solr/search/select?q=*%3A*&wt=json
Request Method: GET
Status Code: 403 
Remote Address: 127.0.0.1:80
Referrer Policy: no-referrer-when-downgrade

在两种情况下,这些都是标题:

Request URL: http://localhost/solr/search/select?q=*%3A*&wt=json
Request Method: GET
Status Code: 200 
Remote Address: 127.0.0.1:80
Referrer Policy: no-referrer-when-downgrade

这是我的Apache http配置:

Access-Control-Allow-Headers: x-requested-with, Content-Type, origin, authorization, accept, client-security-token
Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Connection: Keep-Alive
Content-Length: 0
Content-Type: text/plain
Date: Fri, 24 May 2019 03:15:42 GMT
Keep-Alive: timeout=5, max=94
Server: Apache/2.4.25 (Debian)

和ajax请求:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyRequests Off
    ProxyPass / http://localhost:5553/
    ProxyPassReverse / http://localhost:5553/

    RewriteEngine On                  
    RewriteCond %{REQUEST_METHOD} OPTIONS 
    RewriteRule ^(.*)$ $1 [R=200,L]

    #Headers
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    Header always set Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
    #Header add Access-Control-Allow-Credentials "true"
</VirtualHost>

有帮助吗?

谢谢。

0 个答案:

没有答案