127.0.0.1和localhost是否被浏览器视为两个不同的域? [英] Are 127.0.0.1 and localhost considered as two different domains by browsers?

查看:1223
本文介绍了127.0.0.1和localhost是否被浏览器视为两个不同的域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

127.0.0.1和localhost是否被浏览器视为两个不同的域,因此强制实施跨域(同源策略)限制?

Are 127.0.0.1 and localhost considered as two different domains by browsers and therefore enforce cross-domain (same origin policy) restrictions?

我观察到它工作了一段时间(在简单的网页的情况下),不能使用基于Flex的网页。

I observed it works sometime (in case of simple web pages) and does not work with Flex based web pages.

例如:
场景I:
在一个名为page1.htm的网页中,您可以调用以下脚本:

For example: Scenario I: In a web page called page1.htm, you call a script as follows:

<script type="text/javascript" src="js/somejsscript.js"></script>

<script type="text/javascript" src="http://localhost/js/somejsscript.js"></script>

,您可以以 http://localhost/page1.htm

脚本II:
您可以按如下方式调用脚本:

Scenario II: You call the script as follows:

<script type="text/javascript" src="http://127.0.0.1/js/somejsscript.js"></script>

,您可以以 http://localhost/page1.htm

推荐答案

/ host / port(port是一个方案的默认值,如果它不存在,例如端口80为http,443为https)。同源定义为匹配方案/主机/端口。 localhost和127.0.0.1在这种情况下是不同的主机。请参见 http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules

Origin is defined as a scheme/host/port (port is the default value for a scheme if it doesn't exist, e.g. port 80 for http, 443 for https). Same-origin is defined as a matching scheme/host/port. "localhost" and "127.0.0.1" are different hosts in this case. See http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules

这篇关于127.0.0.1和localhost是否被浏览器视为两个不同的域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆