跨域资源共享(CORS)是否区分HTTP和HTTPS?

Nex*_*tep 18 javascript http xmlhttprequest cors

我有两个站点:https //:www.domain-only-uses-https.com和www.domain-uses-both-http-and-https.com

现在我在前者的页面中制作2个ajax GET请求到后者,一个是

https://www.domain-uses-both-http-and-https.com/some-path  (using the HTTPS scheme) 
Run Code Online (Sandbox Code Playgroud)

而另一个是

http://www.domain-uses-both-http-and-https.com/some-other-path (using the HTTP scheme)
Run Code Online (Sandbox Code Playgroud)

我将DID设置为"https //:www.domain-only-uses-https.com"作为服务器"www.domain-uses-both-http"中"Access-Control-Allow-Origin:"标头的值-and-https.com".

但现在似乎Chrome只允许请求1,但禁止请求2.

所以我的问题是:"Access-Control-Allow-Origin"标题是否区分HTTP和HTTPS?希望我已经明确了......

aps*_*ers 32

是的,HTTP和HTTPS起源不同.

起源是一个组合的主机名,端口方案.

  http://foo.example.com:8080/
  ^^^^   ^^^^^^^^^^^^^^^ ^^^^
   ||           ||        ||
 scheme      hostname    port
Run Code Online (Sandbox Code Playgroud)

如果并非所有这些字段在两个资源之间匹配,则资源来自不同的来源.因此,您必须明确指定资源是使用HTTP方案从原点访问还是使用HTTPS方案来源.

有些浏览器只允许Access-Control-Allow-Origin标头包含*与每个响应一起发送的一个源(或); 但是,您的服务器可以检测请求的Origin标头并在CORS响应中发送相同的源.