我有一个使用webpack-simple选项生成的Vue应用程序.我正在尝试发出GET请求,https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en但我收到错误:
XMLHttpRequest无法加载
https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en.对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.http://127.0.0.1:8080因此,不允许访问" 来源" .
我正在使用vue-resource并添加了:
Vue.http.headers.common['Access-Control-Allow-Origin'] = '*'
Run Code Online (Sandbox Code Playgroud)
那没有效果.
我还在以下devServer选项中添加了这个webpack.config.js:
devServer: {
historyApiFallback: true,
noInfo: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
}
Run Code Online (Sandbox Code Playgroud)
这也不能解决问题; 错误消息保持不变.
如何解决这个问题?
我一直在阅读Dive Into HTML5,Mark提到:
"您可以在HTML5大纲视图中测试自己的页面, 以确保正确使用标题元素."
我已经尝试过这个HTML5大纲,我知道它在功能上概述了我在互联网上找到的其他HTML5页面.
它的问题在于它不适用于所有页面(主要是我为Wordpress主题编写的页面),并且错误消息含糊不清; 它们似乎引用了问题中的问题元素(<section>例如),但是没有做太多工作来指定它在页面上讨论的元素; 即指定行号,就像验证器一样.
我发现一些其他的方案是能够读取HTML5的轮廓,但我担心他们可能是早期的实现,可能是过时的当前HTML5规范.
所以我想知道是否有其他程序,网站等,更简洁的错误消息,我可以测试我的页面,以确保我(HTML5的初学者)正在创建一个文档大纲,可以通过能够阅读的工具正确阅读HTML5文档概述.
假设我在页面上有几个 iframe,其中一个发送了帖子消息。有没有一种简单的跨浏览器方式来检测哪个人做了并能够回复?
我看到了source消息的属性,event但我无法通过使用它来响应event.source.contentWindow.postMessage:
错误:访问属性“contentWindow”的权限被拒绝
我能够发送推送通知,并且在服务工作者中我正在进行服务呼叫我只是想要通过该服务调用发送GCM注册ID.如何在服务工作者中获取注册ID或订阅ID
这是我的代码
self.addEventListener('push', function(event) {
console.log('Received a push message from local', event);
var title = 'My title file. Testing on';
var body = 'New Push Message.';
var icon = 'refresh_blueicon.png';
var tag = 'my-push-tag';
event.waitUntil(
// Here i need to wind GCM Registration id / Subscription id with external service call
fetch('http://localhost/pushMsg/Push_Notification/msg.php').then(function(response){
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
throw new Error();
}
// Examine the text in the response
return …Run Code Online (Sandbox Code Playgroud) google-cloud-messaging chrome-gcm service-worker web-push push-api
根据规范,fetch api有各种缓存模式.("default","no-store","reload","no-cache","force-cache"和"only-if-cached")但是,不清楚每种模式的用途,或者浏览器支持的状态.
我在本地运行Flask-Restful API并从不同的端口发送包含JSON的POST请求.我收到了错误
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
但是,当我跑
curl --include -X OPTIONS http://localhost:5000/api/comments/3
--header Access-Control-Request-Method:POST
--header Access-Control-Request-Headers:Content-Type
--header Origin:http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
我明白了
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Allow: HEAD, GET, POST, OPTIONS
Access-Control-Allow-Origin: http://localhost:8080
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
Vary: Origin
Access-Control-Allow-Headers: Content-Type
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)
其中"Access-Control-Allow-Origin"显示为"*".GET工作正常,只是POST给出了这个错误.怎么可能出错?如果相关,对于我正在使用的前端做出反应并通过axios请求.
我的FE应用程序正在使用来自不同域的API.我知道它应该触发CORS,但据我所知它不应该为每个请求创建预检.
根据文档,我不应该有预检请求的GET方法.
Cross-site requests are preflighted like this since they may have implications to
user data. In particular, a request is preflighted if:
- It uses methods other than GET, HEAD or POST.
Also, if POST is used to send request data with a Content-Type
other than application/x-www-form-urlencoded, multipart/form-data,
or text/plain, e.g. if the POST request sends an XML payload to the
server using application/xml or text/xml, then the request is preflighted.
- It sets custom …Run Code Online (Sandbox Code Playgroud) 我从 chrome 的控制台收到这个错误日志
XMLHttpRequest 无法加载https://subgroup.domain.com/socket.io/?EIO=3&transport=polling&t=Lpgp_mu。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost:3000 '。响应的 HTTP 状态代码为 500。
我正在使用 Node.js、socket.io 在我的节点和 react.js 之间进行通信,使用 digitalocean 的 droplet 使用 nginx 来托管它们。
我已经阅读了很多关于 CORS 错误的信息,但我不确定在哪里修复错误。我一直试图在我的 NGINX 中允许它们
location /server {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Access-Control-Allow-Origin *;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Run Code Online (Sandbox Code Playgroud)
从我的 node.js,服务器端:
var express = require("express");
var app = express();
var http = require("http");
var port = 8080;
var io = require("socket.io").listen(app.listen(port));
app.use("/", function (req, res, next) {
res.status(200).send("Online …Run Code Online (Sandbox Code Playgroud) 我对使用Play的内容安全策略有疑问!框架(2.6).
我已经为项目添加了一个外部库来绘制图表,javascript文件在项目中,图表渲染得很好.
我遇到的问题是我的控制台左右喷出错误.这是我不断得到的错误:
拒绝应用内联样式,因为它违反了以下内容安全策略指令:"style-src'self'".要么是'unsafe-inline'关键字,要么是哈希('sha256-GPjBVmsZjSEoackW5SF7HKgSHcUUBqf1/TJwOl3Co7Y ='),要么是nonce('nonce -...')来启用内联执行.
在搜索如何解决这个问题的过程中,我遇到了一些内容,例如在HTML中包含一个元标记,它在Play中没有做任何事情.我也尝试将ContentSecurityHeader放在application.conf中,如下所述:https: //www.playframework.com/documentation/2.6.x/SecurityHeaders 这也没用.在开发我的项目时,我也遇到了关于default-src'self'的错误,我认为它将是相同类型的修复,而且它与配置有关,我没有做对.
如果有人不得不做这种类型的配置,我会喜欢关于如何正确配置我的应用程序的一些指示.
提前致谢!
configuration playframework content-security-policy playframework-2.6
我的应用在这里加载视频:https://core.arc.io/guanzo/VideoOfPeopleWalking.mp4
它使用Range请求标头以16Kb的块加载来自另一个来源的视频.我的服务器已将响应标头设置Access-Control-Max-Age
为10分钟,以防止出现多余的OPTIONS请求.
访问链接(它是一个HTML页面),打开网络工具,并观察获取16Kb块需要大约1秒.
现在选中"禁用缓存",您应该看到请求更快完成LOT,看起来有更多的并发请求.这与预期行为相反,因为每个请求都必须触发并等待OPTIONS请求.
如果启用了缓存,请求应该更快,不是吗?这里发生了什么?
以下是GIF格式的复制品:https://i.gyazo.com/ec5941829031cdd4dc684a3b53ec6c39.mp4
注意:块存储在IndexedDB中,因此如果刷新页面,则需要清除IndexedDB以强制触发所有请求.
编辑:筛选出任何firestore请求,我不确定为什么这些请求被解雇,但它应该与我的问题无关.
编辑:一个新的线索!https://i.gyazo.com/bd887533a42868f748564ccda4451881.png
选中"禁用缓存"后,Chrome将重复使用"连接ID"列中显示的相同TCP连接.表面上看,这应该可以更快地提出请求.
cors ×4
javascript ×4
angular ×1
axios ×1
caching ×1
chrome-gcm ×1
cross-domain ×1
fetch-api ×1
flask ×1
flask-cors ×1
html ×1
html-heading ×1
html5 ×1
http ×1
nginx ×1
node.js ×1
postmessage ×1
preflight ×1
push-api ×1
python ×1
socket.io ×1
vue-resource ×1
vue.js ×1
web-push ×1
webpack ×1