我正在尝试使用plupload将文件(可能非常大)从一台服务器的网站上传到另一台服务器的后端。让我们说:
domain 1 = http://www.websitedomain.com/uploadform
domain 2 = http://www.backenddomain.com/uploadhandler
尝试上传我发送以下内容:
OPTIONS /main/uploadnetwork.php HTTP/1.1
Host: backenddomain.com
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://www.websitedomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Access-Control-Request-Headers: origin, content-type
Accept: */*
Referer: http://www.websitedomain.com/uploadform
Accept-Encoding: gzip,deflate,sdch
Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
DNT: 1
但是当我尝试开始上传时,服务器返回以下内容:
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Mon, 01 Oct 2012 12:41:57 GMT
Content-Length: 999
在做了一些研究之后,我发现浏览器会检查服务器是否接受预期的消息。看起来我的服务器不想接受简单的POST调用,即使我一直使用post。
Google Chrome控制台出现以下错误:
XMLHttpRequest cannot load http://www.backenddomain.com/uploadhandler. Origin http://www.websitedomain.com is not allowed by Access-Control-Allow-Origin.
有谁知道如何阻止浏览器检查或如何告诉我的服务器只接受POST?
答案 0 :(得分:1)
您似乎面临Same origin policy problem
添加特殊标题应该对某些浏览器有所帮助: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
这个问题的答案可能也有帮助: Cross-domain data access in JavaScript
您还应该检查跨域代码:https://stackoverflow.com/questions/tagged/cross-domain