簡體   English   中英

Access-Control-Allow-Origin在Apache上不起作用

[英]Access-Control-Allow-Origin Not Working on Apache

當我從本地主機到服務器執行ajax發布時,我不斷遇到跨源問題:

OPTIONS http://domain:port/fileuploader/fileupload No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. plupload.full.min.js:14
XMLHttpRequest cannot load http://domain:port/fileuploader/fileupload. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. 

我正在使用apache,所以我添加了它以允許所有內容,但仍然可以正常工作:

 Header add Access-Control-Allow-Origin *
 Header add Access-Control-Allow-Headers "SOAPAction, Authorization, username, password, origin, X-Requested-With, Content-Type, XMLHttpRequest"
 Header add Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
 Header add Access-Control-Allow-Credentials: "true"

我的瀏覽器的響應標頭是:

Request URL:http://domain:port/fileuploader/fileupload
Request Method:OPTIONS
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ar;q=0.6
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Cache-Control:no-cache
Connection:keep-alive
Host:domain:port
Origin:http://localhost
Pragma:no-cache
Referer:http://localhost/omnixuploader/index.html?dDocName=test8818&dDocTitle=test8818&dDocType=SiebelAttachment&dDocAuthor=SADMIN&lan=ara&files=test|jpg:png:txt|220,wwow|pdf:txt:zip|222&rand=19
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Response Headersview source
Allow:GET, HEAD, POST, TRACE, OPTIONS
Content-Length:0
Date:Thu, 09 Jan 2014 14:39:45 GMT
X-ORACLE-DMS-ECID:a3121f70a766128a:-422d6665:14370f7c3a3:-8000-000000000000057a
X-Powered-By:Servlet/2.5 JSP/2.1

我不明白為什么它不起作用? 有什么提示嗎?

您似乎正在配置http://localhost以將權限授予其他站點,以告知瀏覽器對其發出請求。

您需要告訴http://domain:port/來做到這一點。

X-Powered-By:Servlet/2.5 JSP/2.1建議您使用的是Apache Tomcat。 該問題的答案描述如何配置該服務器。

嘗試先設置標題,然后添加其他標題:

Header set Access-Control-Allow-Origin *

Header add Access-Control-Allow-Headers "SOAPAction, Authorization, username, password, origin, X-Requested-With, Content-Type, XMLHttpRequest"

Header add Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"

Header add Access-Control-Allow-Credentials: "true"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM