总而言之,我正在使用像dicom文件的api这样的观众,称为基石,为此,我连接到dc4chee的WADO服务以获取dicom,dcm4chee运行端口8080,我的节点上的应用程序使用端口3000,所以我试图显示浏览器的dicom.
https://www.npmjs.com/package/cornerstone-wado-image-loader
这是浏览器显示的错误
XMLHttpRequest can not load http: // localhost: 8080 / wado? RequestType = WADO & studyUID = 1.2.840.113704.1.111.5 ... 26513.429 & contentType = application% 2Fdicom & transferSyntax = 1.2.840.10008.1.2. In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost: 3000' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
在指定的文档中
请注意,Web服务器必须支持跨源资源共享,否则图像将无法加载.如果您无法在Web服务器上启用CORS,而您正在加载DICOM P10实例,则可以使用反向代理.这是一个基于http-proxy的简单Node.js,它添加了你可能觉得有用的CORS头文件.
并显示此示例代码,但我使用快递,此代码不起作用
Var http = require ('http'),
HttpProxy = require ('http-proxy');
Var proxy = httpProxy.createProxyServer ({target: 'http: // localhost: 8042'}) .listen (8000);
Proxy.on ('proxyRes', function (proxyReq, req, res, …Run Code Online (Sandbox Code Playgroud) 我有一个使用在节点上运行的OAuth 2的Web应用程序.使用EJS模板,我能够正确创建一个工作流,提示用户登录,验证,然后执行"GetUser"GET命令并将输出转储到屏幕.最近我试图删除EJS并希望让AnguarJS正常工作.
目前我已经删除了EJS并实现了Angular,但是有角度很多奇怪的事情发生了,我无法弄清楚为什么!
当我的用户点击"登录"时,他们应该被带到他们使用OAuth 2登录的另一个网站.这个过程在带有EJS的Node上工作正常,但是在我的控制器加载角度时,加载了正确的部分,但是没有数据.使用Chrome DEV工具查看此过程,我看到以下错误
XMLHttpRequest cannot load http://website/oauth/authorize?...
No 'Access-Control-Allow-Origin'
header is present on the requested resource.
Origin 'http://localhost:8080' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
甚至更奇怪的是,在网络选项卡中,我可以看到正确的请求URL!如果我将此URL复制并粘贴到另一个选项卡中,则执行"GetUser"命令,但随后节点崩溃并且我的页面失败.
我尝试过不同的浏览器,启用CORS和配置CORS.我知道问题在于Angular,因为我可以成功地使用与EJS相同的代码.我已将我的Angular代码放在下面,任何帮助都将不胜感激!
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var config = require('./config.js')
var passport = require('passport');
var OAuth2Strategy = require('passport-oauth').OAuth2Strategy;
var session = require('express-session');
var index = require('./routes/index');
var login = require('./routes/login');
var logout …Run Code Online (Sandbox Code Playgroud) 我知道这种问题以前已经解决过,但我无法确切地弄清楚为什么它不适合我的情况。
我正在本地开发一个网站,我想在各种平台和设备上测试它,所以我决定使用 ngrok 来实现这一点。
我的前端在端口 3000 上运行,我的 Express 服务器在端口 5000 上运行。
所以我打开ngrok并输入ngrok http 3000
在我的本地 PC 上,服务器正在运行,它https://example.ngrok.io按预期工作,没有任何问题。
但在我的笔记本电脑(或其他设备)上,前端显示正确,但当它实际上要从后端获取数据时,它显示错误:Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5000/weather/51.87575912475586,0.9436600208282471. (Reason: CORS request did not succeed).
在我的 Express 服务器上,我确保使用 cors 包,并且app.use(cors());我还尝试手动添加标头:
app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
Run Code Online (Sandbox Code Playgroud)
来源:为什么将 CORS 标头添加到 OPTIONS 路由不允许浏览器访问我的 API?
这也是我的代码,我在其中获取和获取数据,以防我在那里做错了什么:
index.js(前端)
const response = await fetch(`http://localhost:5000/weather/${lat},${lng}`); //sending request to server-side
const json = …Run Code Online (Sandbox Code Playgroud) 我正在使用javascript fetch API使用以下代码查询跨域api:
fetch('https://api.com/search?query="2016"').then(function (response) {
console.log(response.headers.get('Access-Control-Allow-Headers'))
console.log(response.headers.get('Content-Range'))
console.log(response.headers.get('Accept-Range'))
console.log(response.headers.get('Date'))
console.log(response.headers.get('Content-Type'))
})
Run Code Online (Sandbox Code Playgroud)
响应标头如下:
Accept-Range:cars 300
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Content-Range, Accept-Range
Access-Control-Allow-Methods:PUT, POST, OPTIONS, GET
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Connection:keep-alive
Content-Range:0-99/1941
Content-Type:application/json
Date:Tue, 12 Jan 2016 12:17:55 GMT
Transfer-Encoding:chunked
Run Code Online (Sandbox Code Playgroud)
非常奇怪的是,只有"Content-Type"适用于其他我得到null:
null
null
null
null
application/json
Run Code Online (Sandbox Code Playgroud)
我需要做什么来检索那些空标题?
我正在使用Angular2 RC5(核心,http等)并尝试连接到启用CORS的Node.js服务器.我的应用程序是从Angular-CLI生成的新版本(版本:"1.0.0-beta.11-webpack.2").
// src/app/app.component.ts
...
ngOnInit () {
const headers: Headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Origin', '*');
const options = new RequestOptions({
headers: headers
});
this.http.get('http://localhost:9000/api/v1/users', options)
.map((res: Response) => res.json())
.subscribe(users => console.log(users));
}
Run Code Online (Sandbox Code Playgroud)
...
当应用程序启动时,OnInit挂钩被调用,我在控制台中出错.这是我收到的错误消息.
EXCEPTION: TypeError: Cannot read property 'toString' of null
browser_adapter.js:84EXCEPTION: TypeError: Cannot read property 'toString' of nullBrowserDomAdapter.logError @ browser_adapter.js:84BrowserDomAdapter.logGroup @ browser_adapter.js:94ExceptionHandler.call @ exception_handler.js:65(anonymous function) @ application_ref.js:267ZoneDelegate.invoke @ zone.js:323onInvoke @ ng_zone_impl.js:53ZoneDelegate.invoke @ zone.js:322Zone.run @ zone.js:216(anonymous function) @ zone.js:571ZoneDelegate.invokeTask @ zone.js:356onInvokeTask …Run Code Online (Sandbox Code Playgroud) 我有单独的restfull网络服务。我在我的前端项目中使用 Angular 6。当我使用 httpClient 发布数据时,出现这样的错误
error => cors header 'access-control-allow-origin' missing
Run Code Online (Sandbox Code Playgroud)
这是我的角度代码:
login(username:string , password:string){
var param = "username=" +username + "&password=" + password ;
return this.http.post("http://localhost:8080/login",param);
}
Run Code Online (Sandbox Code Playgroud) 我是node.js的新手并且遇到了cors问题.我正在从一个快递服务器向另一个快递服务器发送客户端ajax get请求,但至少我无法从app.all('*', function(req, res, next){console.log("request: "+req)})
GET请求获得响应,如下所示:
$.ajax({
type: 'GET',
url: 'http://localhost:8082/request'
});
Run Code Online (Sandbox Code Playgroud)
我还在ajax中设置标题:
'beforeSend : function(xhr) {
xhr.setRequestHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Max-Age', '1000');
xhr.setRequestHeader('Authorization', '*')},
Run Code Online (Sandbox Code Playgroud)
...或在node.js中设置cors模块:
var cors = require('cors');
var app = express();
app.use(cors());
app.options('*',cors(),function(){
console.log("preflight")
});
Run Code Online (Sandbox Code Playgroud)
在firefox和chrome中,我没有得到任何响应(我得到了chrome net::ERR_CONNECTION_REFUSED)当我在PC上本地运行节点服务器时,一切正常.curl命令工作正常.有机会,这是托管/端口的问题还是我还缺少什么?
我尝试构建一个平台,它由两个独立的部分组成:后端和前端。\n后端由 Express.js 和 Passport.js 提供支持。它可以通过 localhost:3000 获得。\n前端使用 Googlespolymer-1.0 并在 localhost:8001 上运行。
\n\n我想在我的后端完成所有 API 工作。Ui调用并从后端获取数据。
\n\n当尝试对我的后端路由进行 Iron-ajax 授权请求时,我收到 CORS 错误:
\n\nXMLHttpRequest 无法加载 http://localhost:3000/auth/facebook。\n请求已重定向到 \'https://www.facebook.com/v2.2/dialog/oauth?response_type=code&redirect_uri=\xe2\x80\ xa6%3A3000%2Fauth%2Ffacebook%2Fcallback&scope=email&client_id=0815\', \n对于需要预检的跨域请求是不允许的。\n\n
用户界面片段:
\n\n\n\niron-ajax\n id="login"\n url=""\n method="GET"\n headers=\'{"X-Requested-With": "XMLHttpRequest"}\'\n 句柄-as="json"\n on-response="hresponse"\n debounce-duration="300">\n/iron-ajax>\n\n\n_handleTap: function () {\n var url = \' http://localhost:3000/auth/\' + this.service;\n this.$.login.url = url;\n this.$.login.generateRequest(); \n},\n\n\n后端片段:
\n\n\napp.get(\'/auth/facebook\', Passport.authenticate(\'facebook\', { range: \'email\' }));\n\napp.get(\'/auth/facebook/ callback\', Passport.authenticate(\'facebook\'), function(req, res) {\n res.status(200).json({\n success: true,\n message: \'享受!\' ,\n 重定向: \'/route/to/nowhere\',\n }).end();\n });\n\n\n\n … 我有一个包含大约 100 万个对象的大型 json 映射,每个对象包含大约 200 个键值对。例如。[{key1 : val1, key2 : val2, ...}, {key1 : val3, key2 : val4, ...}]
正如您所看到的,这里的键被复制了,每个键都意味着一个新的 String 对象。有没有其他方法可以让我说所有重复的键都应该指向同一个 String 对象以减少 map 的内存大小。有了上述统计数据,浏览器会因超过 1Gb 的内存而爆炸。
我在后端使用 nodejs express 作为我的 API。我想知道如何在redirect方法上启用 CORS 。
以下是我的快速重定向代码:
res.redirect(redirectUrl);
Run Code Online (Sandbox Code Playgroud)
当客户端向上述 API 发送请求时,它会将请求重定向到 as3但我收到以下错误:
Access to XMLHttpRequest at 'https://s3-ap-southeast-
2.amazonaws.com/index.html' (redirected from
'http://localhost:9090/v0/api') from origin 'http://localhost:9090' has
been blocked by CORS policy: Response to preflight request doesn't pass
access control check: No 'Access-Control-Allow-Origin' header is present on
the requested resource.
Run Code Online (Sandbox Code Playgroud)
前端正在运行,http://localhost:9090并且前端域已添加到 s3 存储桶中的 CORS 上。如果我https://s3-ap-southeast-2.amazonaws.com/index.html直接从浏览器发送请求,它工作正常。所以我认为问题出在nodejs express redirect方法上。如何为重定向启用 CORS?
我知道如何启用,CORS但我的问题与redirect. 我怎样才能使重定向工作?
cors ×6
node.js ×6
express ×5
angularjs ×3
javascript ×3
angular ×2
passport.js ×2
ajax ×1
amazon-s3 ×1
dicom ×1
fetch-api ×1
http-headers ×1
localhost ×1
ngrok ×1
polymer ×1
polymer-1.0 ×1
string ×1