ie and chrome difference for cross-domain localhost

I believe that even now I do not fully grasp the cross-domain.

  • Cross-domain is a browser behavior
  • In fact, cross-domain request will be sent to the server
  • Server-side cross-domain problem can be solved by the client cors
  • nginx reverse proxy configuration to solve cross-domain problems
  • Protocol, domain names, ports are taken into account, such as http://11.11.11.11:8888/index.html access http://11.11.11.11:8899/interface there will be cross-domain issues

These are common sense, I would say that today is a difference in ie and chrome I found that for the last of the above, the domain name is in the case of localhost. Let me get down to business.

Let me talk about the conclusion:

How do I prove it?
I wrote the following simple node program

// server.js
// 需要安装npm i --save express cookie-parser
var express = require('express');
var cookieParser = require('cookie-parser');
var app = express();

app.use(cookieParser());
app.all('*', function(req, res, next) {
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Access-Control-Allow-Headers', 'X-Requestd-With');
	res.header('Access-Control-Allow-Method', 'PUT, POST, GET, DELETE, OPTIONS');
});
app.get('/', function(req, res) {
	console.log('Cookies:', req.cookies);
	res.cookie('newdate', new Date(), {maxAge: 600000});
});
app.listen(8888);

// index.html
// 需要安装npm i --save-dev http-server,用来host index.html页面
<!doctype html>
<html
	<head></head>
	<body>
		<button id="btn">click</button>
		<script>
			var btn = document.getElementById('btn');
			btn.onclick = function() {
				var xhr = new XMLHttpRequest();
				xhr.open('http://localhost:8888');
				xhr.send();
			}
		</script>
	</body>
</html>

http: // localhost: 8888 every time upon request, the cookie will be printed out for easy observation.
In fact, this discovery did not much use, just want to record it :)

Published 53 original articles · won praise 39 · views 80000 +

Guess you like

Origin blog.csdn.net/Chinese521/article/details/96274412