Tag: cors

我的节点应用程序中的CORS不起作用

一个网站正在做一个XMLHttpRequest到我的节点应用程序,但他们得到以下错误: XMLHttpRequest cannot load http://[MY IP]/start. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.[THEIR WEBSITE].com' is therefore not allowed access. The response had HTTP status code 504. 这是他们的XMLHttpRequest请求: var xhr = typeof XMLHttpRequest === "undefined" ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest; xhr.open("POST", 'http://[MY IP]/myapp', true); xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.send(JSON.stringify(data)); 这是节点应用程序中的代码(…表示不相关的代码): … var cors […]

如何将plunker连接到本地Node.js服务器?

我想将我的plunk连接到在本地机器上运行的节点服务器。 我想实现这个目的是为了从数据库中获取一些数据。 目前,我已经在我的plunk上的app.js文件中创build了一些示例数据。 有没有办法做到这一点? 如果不是,那么有什么替代方法可以在线运行Node.js应用程序?

Google OAuth2:redirect已被CORS策略阻止:请求需要预检,不允许跟踪跨源redirect

尝试实施Google OAuth2并使用https://github.com/google/google-api-nodejs-client#authorizing-and-authenticating作为参考。 将用户redirect到这样的同意页面时 var url = oauth2Client.generateAuthUrl({ access_type: 'offline', scope: some_scope }); res.redirect(url); 我在浏览器控制台中看到这个错误(编辑链接): XMLHttpRequest无法加载localhost:8080 / myPageName。 从localhost:8080 / myPageNameredirect到accounts.google.com/o/oauth2/auth?access_type = …已被CORS策略阻止:请求需要预检,不允许跟踪跨源redirect。 奇怪的是我得到这个错误只有当执行从GUI(用户按下button; angular2前端)的stream程。 当我把localhost:8080 / myPageName直接放到浏览器的地址栏中时,一切正常(取得同意书表格,然后是令牌)。 任何帮助表示赞赏。 谢谢。

我怎样才能从浏览器发送一个大文件到Node.js服务器?

我试图使用data: URL从客户端发送到服务器的图像。 我读取上传的图像并将数据发送到服务器的function非常简单: getTags = event => { const file = event.target.files[0]; if (!file.type.match('image.*')) { return; } const reader = new FileReader(); reader.onload = (theFile => { return (e) => { this.sendDataToServer(e.target.result, theFile.type); }; })(file); reader.readAsDataURL(file); } sendDataToServer = (data, fileType) => { const options = { method: 'POST', headers: { 'Content-Type': fileType, }, body: […]

Angular2 http向其他端口上的nodejs服务器发送请求

我有一个在localhost:4200上运行的angular2应用程序,在localhost:3000上运行nodejs服务器。 我想用http.post将数据发布到服务器,但是在req.body或req.params的nodejs服务器中我得到了未定义的数据。 起初,我有从服务器呈现的angular2应用程序,这意味着我只有localhost:3000的nodejs,我根本没有任何问题,所以这不是sytax问题,但是当我想分开客户端和服务器,我不能'不发表任何要求。 GET请求的作品。 我有TodoService与服务器交互,并具有saveTodofunction。 newTodo是有效的,console.log提供了正确的信息。 我试过发布json和张贴与url-params和两个不工作:发布json: saveTodo(newTodo: any) { let headers = new Headers(); headers.append('Content-Type','application/json'); return this.http.post('/api/v1/todo', JSON.stringify(newTodo), {headers: headers}) .map(res => res.json()); } 发布url参数: saveTodo(newTodo: any) { let headers = new Headers(); headers.append('Content-Type','application/x-www-form-urlencoded'); let body = new URLSearchParams(); body.set('newTodo', newTodo); return this.http.post('/api/v1/todo', body, {headers: headers}) .map(res => res.json()); } 我从组件中调用这个函数: addTodo(event: any) { […]

在phonegap应用程序的node.js服务器上使用CORS

我试图连接我的cordova / phonegap应用程序与我的node.js服务器。 问题是,我得到这个错误"XMLHttpRequest cannot load http://127.0.0.1:1234/api/users. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access. The response had HTTP status code 500. " 。 我尝试添加这个中间件到我的node.js服务器,进入我的phonegap域,然后,当然,只是为了testingpurpouses,我想我会允许所有域的CORS,仍然没有运气。 这是我在我的node.js服务器上使用的: app.use(function (req, res, next) { // Website you wish to allow to connect res.setHeader('Access-Control-Allow-Origin', '*'); // Request methods you wish to […]

IIS中的CORS使用凭证和通配符在Access-Control-Allow-Origin中发出

我inheritance了一个相当基本的网站,提供数据和处理一些套接字连接。 它使用iisnode作为桥梁运行IIS后面的NodeJS。 从“服务正常页面”的angular度来看,这一切都很好。 部分问题是与服务器的实际连接来自桌面客户端,其中内容通过不同的应用程序作为小工具加载,以及来自networking,移动设备等的潜在改变和变化的部分。即,未知数量的客户端域。 我已经设置访问控制,允许起源*,只是打开谷仓门,但现在在客户端中得到以下错误: 11:29:57.668跨域请求被阻止:相同的源策略不允许在' http://server/socket.io/?EIO = 3&transport = polling&t = 1486150196479-0 '处读取远程资源。 (原因:如果CORS头“Access-Control-Allow-Origin”为'*',则不支持凭据)。 1(未知) 我试图将访问控制允许的证书明确地设置为假(也是如此,以及完全抛弃),但我的任何尝试都没有让我过去这一点。 原始响应标题看起来像这样: Access-Control-Allow-Credentials: false Access-Control-Allow-Headers: Origin,Content-Type,Accept Access-Control-Allow-Methods: GET,HEAD,PUT,POST,DELETE,OPTIONS Access-Control-Allow-Origin: * Cache-Control: no-cache Content-Encoding: gzip Content-Length: 969 Content-Type: text/html Date: Fri, 03 Feb 2017 19:30:21 GMT Server: Microsoft-IIS/8.5 Vary: Accept-Encoding X-Powered-By: ASP.NET 在过去几天看到很多CORS网站和文章后,我似乎无法理清为什么它仍在抱怨证书 – 更具体地说,我该如何解决这个问题? 谢谢! 更新2017-02-06 客户端代码并不令人兴奋。 由于服务器是IIS后面的NodeJS,所以我真正为此做的是实现套接字连接: var […]

angular度$ http请求从80端口到另一个端口

我试图从一个angular度1项目使用$ http方法来打击本地服务器上的端口3000的节点API,但我得到这个错误: XMLHttpRequest无法加载http:// localhost:3000 / login 。 请求标头字段预检响应中的Access-Control-Allow-Headers不允许授权。 我还在节点js中添加了Access-Control-Allow-Origin : * : req.on('end', function() { req.rawBody = req.rawBody.toString('utf8'); res.setHeader('Access-Control-Allow-Origin', 'http://localhost'); // Request methods you wish to allow res.setHeader('Access-Control-Allow-Methods', '*'); // Request headers you wish to allow res.setHeader('Access-Control-Allow-Headers', '*'); // Set to true if you need the website to include cookies in the requests sent // […]

如何允许访问不同的端口?

Amber Smalltalk IDE与一个用nodejs编写的服务器一起工作。 如何configurationXMLHttpRequests到同一个域的不同端口的服务器? 琥珀色的默认访问权限是 http://127.0.0.1:4000/ 并检索和存储JSON数据我想使用一个couchDB实例(默认端口是5984) | req | req := XMLHttpRequest new. req open: 'GET' url: 'http://127.0.0.1:5984/' asynchronous: false. req send: ''. 问题 由于跨域访问策略,访问是不可能的。 笔记 服务器被调用 amber-master\bin\server.bat 服务器在 amber-master\cli\js\amber-cli.js 客户端是Firefox,它应该允许XMLHttpRequest对象可以访问不同的端口,只要服务器用“Access-Control-Allow-Origin头”来指示。 参考 http://www.w3.org/TR/cors/#access-control-allow-origin-response-header CouchDB从XMLHttpRequest跨域访问? MKroenert回答之后 我升级到CouchDB 1.4.0版本,并调整local.ini文件以允许CORS(C:\ Program Files \ Apache Software Foundation \ CouchDB \ etc \ couchdb \ local.ini) [httpd] enable_cors = […]

Node.js CORS导致403 Forbidden

我们的网站使用HTML5抓取API来调用我们的后端NodeJS服务来执行某些操作。 我们的后端驻留在与主站点不同的域中,因此我们在Node应用程序上启用了CORS。 这为我们的客户99%的工作。 但是,一个客户一直有问题。 他们试图从他们的工作场所访问我们的网站(也许他们的工作场所networking有更高的安全设置..?),他们收到以下错误: api.our-node-backend.com/blah无法加载资源:服务器的状态为403(Forbidden)书:1提取API无法加载https://api.our-node-backend.com/blah 。 对预检请求的响应不会通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。 原因' https://www.our-frontend-website.com '因此不允许访问。 响应的HTTP状态码为403.如果一个不透明的响应满足您的需求,请将请求的模式设置为“no-cors”,以取消禁用CORS的资源。 我们的Node应用程序目前configuration如下: app.use(function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'Content-Type'); next(); }); // respond to options pre-flight app.options('*', function(req, res) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'Content-Type'); res.status(200).send(); }); 这个configuration有什么问题吗? 堆栈溢出的其他示例将Access-Control-Allow-Headers设置为“Origin,X-Requested-With,Content-Type,Accept”而不是“Content-Type”。 这有什么不同?