跨地资源共享 [英] Cross Origin Resource Sharing
问题描述
您好,我一直在做一些阅读的CORS。
Hello I've been doing some reading on "CORS".
我想我理解这个概念。但是我在执行跨域POST请求一定的难度。
I think I understand the concept. However I'm having some difficulty performing a cross domain POST request.
我已经设置了两个考点在我的本地IIS。
I've set up two test sites on my local IIS.
http://localhost/CORSService/hello.html
http://localhost:8000/CORSClient/index.html
目前,以下code工作:
Currently, the following code works:
<html>
<head>
<title></title>
<script src="jquery-1.4.3.js" type="text/javascript" language="javascript"></script>
</head>
<body>
This is my Hello World: "<span id="helloSpan" style="color: red"></span>"
<script>
$.ajax({
url: "http://localhost/CORSServer/hello.html",
type: "GET",
data: {words: ["tes"]},
dataType: "json",
cache: false,
contentType: "application/json",
success: function(result)
{
$("#helloSpan").html(result.words[0]);
},
error: function(a, b, c)
{
$("#helloSpan").html(a + ' ------- ' + b + ' ------- ' + c);
}
});
</script>
</body>
</html>
然而,当我修改键入从 GET 的到的 POST 的,我收到了405不允许的方法,错误。
However, as soon as I change the type from "GET" to "POST", I receive a 405 Method Not Allowed, error.
我在主持IIS7.5考点。我已经添加了以下HTTP响应头托管在现场的http://本地主机/ CORSServer
I'm hosting the test sites in IIS7.5. I've added the following HTTP Response Headers to the site hosted at http://localhost/CORSServer
Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Methods: POST
Access-Control-Allow-Credentials: true
我可能误解我读过的来源,我假设跨域发布,请与CORS?
I may be misunderstanding the sources I've read, I'm assuming that Cross Domain POSTing is available with CORS?
任何人都可以看到我在做什么错了,还是有我误解的东西吗?
Can anyone see what I'm doing wrong, or have I misunderstood something?
干杯,
詹姆斯
推荐答案
这可能是这样的: http://support.microsoft.com/kb/942051/en-us
第2
代替把的 HTTP请求到一个静态的HTML页面, 通过发送使该HTTP请求 POST方法的Active Server Pages (ASP)页。
Instead of making the HTTP request to a static HTML page, make the HTTP request by sending the POST method to an Active Server Pages (ASP) page.
这篇关于跨地资源共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!