我正在尝试连接到API并发送身份验证标头.我正在使用这里描述的Base64 如何在angularjs中获得基本的auth工作?
function Cntrl($scope, $http, Base64) {
$http.defaults.headers.common['Authorization'] = 'Basic ' + Base64.encode('----myusername----' + ':' + '----mypass---');
$http({method: 'GET', url: 'https://.../Category.json'}).
success(function(data, status, headers, config) {
console.log('success');
}).
error(function(data, status, headers, config) {
alert(data);
});
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误
XMLHttpRequest无法加载https://.../Category.json?callback = ?. 请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源' http://....com '访问.响应具有HTTP状态代码400.
我有 InfluxDB 运行localhost:8086(它是默认的)和一个运行在不同端口上的 go 程序(因为它必须,也不能在 8086 上运行)。我试图在我的 go 程序中使用 JavaScript 将数据发布到 InfluxDB,我得到了No Access-Control-Allow-Origin响应。这个 github 问题(由使用反向代理的人发布)说这个问题可以通过配置代理机制来解决,但我没有使用代理机制。有没有办法在没有得到响应的情况下将数据发布到 InfluxDB?通过 post 请求接收数据似乎是 InfluxDB 的核心功能,但它无法正常工作。
我的Amazon S3存储桶有以下CORS配置.问题是配置似乎完全被忽略了.从存储桶请求对象时,我没有获得任何Access-Control-Allow-Origin标头.是否有任何家庭有类似的问题或调试提示?
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://www.example.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>http://localhost:8100</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
Run Code Online (Sandbox Code Playgroud)
这是我的保管政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example.com/*"
}
]}
Run Code Online (Sandbox Code Playgroud) 我的网站上有一些外部脚本存在一些奇怪的问题.我终于把它归结为这个片段了.
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js" onload="console.log('conversion')"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" onload="console.log('jquery')"></script>
Run Code Online (Sandbox Code Playgroud)
在firefox中加载这个只有第二个脚本加载,而使用chrome,都加载.这是在OSX上使用最新的浏览器.
现在,如果我将crossorigin属性添加到两个脚本,那么它将停止在chrome中使用此错误Script from origin 'http://www.googleadservices.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.example.com:3000' is therefore not allowed access.
现在的脚本是
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js" onload="console.log('12123')" crossorigin async></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" onload="console.log('123')" async crossorigin></script>
Run Code Online (Sandbox Code Playgroud)
我对这种行为上的差异感到震惊.这是因为firefox比CHrome更严格吗?这是我设置的地方吗?或者这是Firefox/Chrome方面的错误?
另外,我应该与供应商讨论如何为CORS设置js?令我印象深刻的是谷歌失败了,但我还有另一个资源破裂.
通过权利,MDN声称script标签不受同一原产地政策的限制.
我必须从我的网站到第三方域/服务器进行Web服务调用.虽然我使用jQuery Ajax通过Post方法使用content-type:text/plain进行此调用,但它工作正常.
但是当我将其更改为content-type:text/xml时,它会抛出:
对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.
即使它设置在第三方服务器上,以允许访问我们的网站.我们在使用content-type:text/plain进行调用时获取此标题.
我们还在Thirdparty服务器上添加了以下内容.
Access-Control-Allow-Methods : Get , Post , Options ,PUT
Access-Control-Allow-Headers: Authorization,origin, content-type, accept
Run Code Online (Sandbox Code Playgroud)
请让我知道飞行前请求没有得到"Access-Control-Allow-Origin"作为回应的原因是什么?
我遇到过一种情况,我从 Angular 6 应用程序调用 Spring Boot 应用程序。当我以与在不同端口上运行的应用程序的角度调用 HTTP post 方法时,它会引发异常。
从源“ http://localhost: 4200 ”访问位于“http://localhost:8080/api”的XMLHttpRequest已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:它没有 HTTP好的状态。
我的 Angular 应用程序在“ http://localhost:4200 ”上运行,端口号:4200 我的 Spring Boot 应用程序在“ http://localhost:8080/api ”上运行:端口号:8080。
没有直接的答案可以解决这个问题。有一些技巧可以禁用 Chrome 中的安全性,使用 NGINX 可以解决此问题。
For several years we have successfully been uploading videos via the YouTube API using some custom JavaScript code. The code was based on some samples provided by Google (cors_upload.js). It's not something we use a lot, just every couple of weeks.
Things were working fine a couple weeks ago, but it has come to my attention that things recently stopped working. We login fine, we obtain the channel info fine. But when we start the upload (which happens via XHR …
我发誓,我曾经在某个方面看过一篇关于此事的文章但却找不到......
如何在另一个域上执行POST类型的jQuery ajax请求?必须在没有代理的情况下完成.这可能吗?
我正在将第三方照片上传服务与我的应用集成.所以我通过iframe将它加载到我的页面中.
当上传服务完成上传我的照片后,它可以触发某个事件到我的父页面,即:
parent.$('body').trigger('photoUpload.complete');
Run Code Online (Sandbox Code Playgroud)
或者它在父页面中触发一个函数,即:
window.parent.reloadParentPage();
Run Code Online (Sandbox Code Playgroud)
无论如何,我在Chrome控制台中收到此警告:
Uncaught SecurityError: Blocked a frame with origin "https://photoupload.com" from accessing a frame with origin "https://website.com".
Run Code Online (Sandbox Code Playgroud)
我意识到这是一个安全问题,如下所述:
http://www.w3.org/TR/2008/WD-access-control-20080912/
所以我想让原点https://photoupload.com访问我的网站.我在我的控制器中这样做了:
after_filter :set_access_control_headers
Run Code Online (Sandbox Code Playgroud)
然后方法:
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = "https://photoupload.com"
headers['Access-Control-Request-Method'] = '*'
end
Run Code Online (Sandbox Code Playgroud)
请注意,这不是https://photoupload.com照片上传服务,https://website.com而是我的网站.(例如清酒的虚构名称),但它们都托管在heroku上.
我该如何工作?
看到人们用这个成功的类似问题:
更新
也许更好的问题是,我应该在哪个应用程序中设置标题?我在我的应用程序中假设?
更新II
有一个更好的方法吗?将iframe中的action/event/something发送到父页面,因此父页面可以以某种方式作出反应
我运行 axios get 方法来调用 php 脚本。但是请求发送两次如何解决这个问题。我的功能:-
axios.get('http://13.233.179.174/customers_log.php',{
headers: {
'Access-Control-Allow-Origin': '*'
},
})
.then(function (response) {
$("#spinner").hide();
console.log('this is response work');
console.log(response.data);
})
.catch(function (error) {
$("#spinner").hide();
console.log(error);
})
Run Code Online (Sandbox Code Playgroud) cors ×4
jquery ×3
cross-domain ×2
javascript ×2
ajax ×1
amazon ×1
amazon-s3 ×1
angular ×1
angular6 ×1
angularjs ×1
firefox ×1
html ×1
http ×1
iframe ×1
influxdb ×1
preflight ×1
script-tag ×1
spring-boot ×1
vue.js ×1
youtube-api ×1