CORS跨域请求
CORS跨域请求 允许跨域请求 只需要在服务器设置响应头 Access-Control-Allow-Origin , 不然的话可以从服务器拿到响应,但是浏览器不会把这个响应显示出来。 (index):1 Access to XMLHttpRequest at 'http://localhost:9001/demo/name' from origin 'http://localhost:9002' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 方案: response.setHeader("Access-Control-Allow-Origin", "http://localhost:9002"); 请求响应中会携带:Access-Control-Allow-Origin: http://localhost:9002 访问成功,可以获取数据。 Access-Control-Allow-Origin: http://localhost:9002 Content-Length: 6 Content-Type: text/html;charset=UTF-8 Date: Fri, 01 Nov 2019 01:24