
http://www.example.com/dir2/other.html:同源http://example.com/dir/other.html:不同源(域名不同)http://v2.www.example.com/dir/other.html:不同源(域名不同)http://www.example.com:81/dir/other.html:不同源(端口不同)
(1) Cookie、LocalStorage 和 IndexDB 无法读取。(2) DOM 无法获得。(3) AJAX 请求不能发送。
document.domain = ‘example.com‘;
document.cookie = ‘name=dudu‘;
var cookieA = document.cookie
const express = require(‘express‘);var serve = express();serve.use(‘/aaa‘,function(req,res){res.cookie(‘user‘,‘name‘,{ path:‘/‘, maxAge:24*3600*1000 , domain:.example.com});res.send(‘ok‘);})serve.listen(8888);
- url #hash
跨文档通信API(Cross-document messaging)
var src = originURL + ‘#‘ + data;document.getElementById(‘myIFrame‘).src = src;
window.onhashchange = checkMessage;function checkMessage() {var message = window.location.hash;// ...}
var popup = window.open(‘http://bbb.com‘, ‘title‘);popup.postMessage(‘Hello World!‘, ‘http://bbb.com‘);
var img = new Image();img.onload = img.onerror = function () {alert(‘done!‘);}img.src = ‘http://7xvi3w.com1.z0.glb.clouddn.com/cors_CFE74C5D-058B-468C-9D0A-8AD9931214B9.png?name=dudu‘
function handleResponse (res) {console.log(res)}var script = document.createElement(‘script‘);script.src = ‘http://freegeoip.net/json/?callback=handleResponse‘;document.body.insertBefore(script,document.body.firstChild);

1) 请求方法是以下三种方法之一:HEADGETPOST(2)HTTP的头信息不超出以下几种字段:AcceptAccept-LanguageContent-LanguageLast-Event-IDContent-Type:只限于三个值application/x-www-form-urlencoded、multipart/form-data、text/plain
Access-Control-Allow-Origin: http://api.bob.com // 请求的origin ,*Access-Control-Allow-Credentials: true // 不要发送cookie, 没有该字段,发送cookie 设为trueAccess-Control-Expose-Headers: FooBar //getResponseHeader() 只能拿到6个基本字段,多的在这里设置;
var xhr = new XMLHttpRequest();xhr.withCredentials = true;
GET /chat HTTP/1.1Host: server.example.comUpgrade: websocket // 这两行切换成websocket 通信Connection: UpgradeSec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==Sec-WebSocket-Protocol: chat, superchatSec-WebSocket-Version: 13Origin: http://example.com //表示该请求的请求源(origin),即发自哪个域名。
HTTP/1.1 101 Switching ProtocolsUpgrade: websocketConnection: UpgradeSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=Sec-WebSocket-Protocol: chat
一致性验证。比如我们从网上下载了某个文件,网站上一般会给出该文件的MD5值,我们下载下来后,可以利用工具计算出新的MD5值,与正确的MD5值进行对照,如果不一样,则可以断定该文件下载出错或被篡改了。数字签名。可以用MD5算法对发布的程序或发布的消息生成MD5值作为签名等。密码存储。在传输过程中或存储过程中,直接用明文的密码都是很危险的。可以在传输之前先用MD5加密,存储也不用存储明文,可以直接存储MD5值。在验证时,先把输入的密码转换成MD5值再与存储值进行对比。MD5的一个实现版本:
原文:http://www.cnblogs.com/dujuncheng/p/2911baa32adf0332d11352e4471c7b01.html