我对使用.htaccess文件了解不多.我试过研究.所以,也许有人可以帮助我在这里.我想同时允许https和http.让我解释.
http正在运行,但HTTPS上的网站在控制台中给我一个错误
XMLHttpRequest无法加载https://domain1.com/data.json."Access-Control-Allow-Origin"标头的值为" https://www.domain1.coms ",不等于提供的来源.因此,不允许来源" https://www.domain1.com "访问.
如果我将"http"更改为" https ",则适用于https网站,但http网站不起作用.我如何同时允许两者?
我希望这对你们有意义!感谢您的任何帮助!
这是我的代码:
<IfModule mod_headers.c>
SetEnvIf Origin "http(s)?://(www\.)?(domain.com|domain2.com|domain3.com|domain4.com|domain5.com)$" AccessControlAllowOrigin=$0$1
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</IfModule>
Run Code Online (Sandbox Code Playgroud) 我正在使用fetch API从其他API获取数据这是我的代码:
var result = fetch(ip, {
method: 'get',
}).then(response => response.json())
.then(data => {
country = data.country_name;
let lat = data.latitude;
let lon = data.longitude;
//fetch weather api with the user country
return fetch(`https://api.darksky.net/forecast/efc76f378da9a5bd8bb366a91ec6f550/${lat},${lon}`);
})
.then(response => response.json())
.then(data => {
// access the data of the weather api
console.log(JSON.stringify(data))
})
.catch(error => console.log('Request failed', error));
Run Code Online (Sandbox Code Playgroud)
但我在控制台中遇到错误:
Fetch API cannot load https://api.darksky.net/forecast/efc76f378da9a5bd8bb366a91ec6f550/52.3824,4.8995. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If …
Run Code Online (Sandbox Code Playgroud) 我是 Cloudflare Workers 的新手。
如何在 Cloudflare Workers 中设置 CORS?
response = await cache.match(cacheKey);
if (!response) {
// handle fetch data and cache
}
const myHeaders = new Headers();
myHeaders.set("Access-Control-Allow-Origin", event.request.headers.get("Origin"));
return new Response(JSON.stringify({
response
}), {
status: 200, headers: myHeaders
});
Run Code Online (Sandbox Code Playgroud) 嗨,我正在实施rest apis,为此我想要允许交叉原始请求.
我目前在做什么:
AWS上的Go-server代码:
func (c *UserController) Login(w http.ResponseWriter, r *http.Request, ctx *rack.Context) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
...
...
c.render.Json(w,rsp, http.StatusOK)
return
}
Run Code Online (Sandbox Code Playgroud)
localhost上的Ajax代码:
<script>
$( document ).ready(function() {
console.log( "ready!" );
$.ajax({
url: 'http://ip:8080/login',
crossDomain: true, //set as a cross domain requests
withCredentials:false,
type: 'post',
success: function (data) {
alert("Data " + data);
},
});
});
Run Code Online (Sandbox Code Playgroud)
我在浏览器控制台上收到以下错误: XMLHttpRequest无法加载http:// ip:8080/login.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源' http:// localhost:8081 '访问.响应具有HTTP状态代码422.
我尝试添加预检选项:
func corsRoute(app *app.App) {
allowedHeaders := "Accept, Content-Type, Content-Length, …
Run Code Online (Sandbox Code Playgroud) 启用CORS有几个安全问题:
但是,对于支持全局CORS的公共和只读Web服务,我有什么问题吗?
Access-Control-Allow-Origin: *
Run Code Online (Sandbox Code Playgroud)
我的假设:
我正在尝试从localhost访问Deezer API,但我一直收到以下错误:
Fetch API cannot load http://api.deezer.com/search/track/autocomplete?limit=1&q=eminem.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost' is therefore not allowed access.
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Run Code Online (Sandbox Code Playgroud)
localhost的响应标头确实有Access-Control-Allow-Origin标头(Access-Control-Allow-Origin:*).
我使用的是像获取:
fetch('http://api.deezer.com/search/track/autocomplete?limit=1&q=eminem')
.
我究竟做错了什么?
我目前遇到一个关于 CORS(跨源资源共享)的问题,奇怪的是,只有当我使用 www.url 前缀时,才会出现这种情况。
\n\n例如,当我使用网址“ http://example.com/index ”访问我的网站时,一切正常并且所有资源都已正确加载。但是,当我尝试使用网址“ http://www.example.com/index ”访问我的网站时,我收到错误Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/index. (Reason: CORS header \xe2\x80\x98Access-Control-Allow-Origin\xe2\x80\x99 missing).
我尝试加载的资源是一个 XML 文件,使用以下代码:
\n\nfunction loadXML()\r\n{\r\n var xhttp = new XMLHttpRequest();\r\n xhttp.onreadystatechange = function() {\r\n if (this.readyState == 4 && this.status == 200) {\r\n xmlData = xhttp.responseXML;\r\n initStartShot();\r\n }\r\n };\r\n xhttp.open("GET", "http://example.com/XML/someXMLfile.xml", true);\r\n xhttp.send();\r\n}
Run Code Online (Sandbox Code Playgroud)\r\n我的所有资源文件都与我的页面位于同一域中。
\n\n我已经四处寻找与我相关的问题,但大多数都是关于 CORS 的一般问题,以及如何让它发挥作用。但事实上我没有任何 CORS 问题,没有“www”前缀,这似乎不适用于我的问题。
\n\n …我正在尝试使用纯 javascript 制作 Spotify 身份验证流程,以便用户可以登录,然后我可以为他们的帐户添加新的播放列表。根据我阅读的说明,我使用了一个身份验证弹出窗口,一旦他们登录,URL 中就会有访问令牌。我现在有一个弹出窗口,用户可以使用它进行身份验证,一旦他们这样做,URL 中就会有访问令牌。
我需要从弹出窗口中获取 url 并将其保存为全局变量,但我无法弄清楚如何在 javascript 中执行此操作。
https://codepen.io/martin-barker/pen/YzPwXaz
我的 codepen 打开一个弹出窗口let popup = window.open(
,我可以在弹出窗口中运行一个函数来检测用户何时成功通过身份验证和 url 更改吗?在这种情况下,我想保存解析的 url 并关闭我的弹出窗口
我的javascript代码如下:
async function spotifyAuth() {
let result = spotifyLogin()
}
//open popup
function spotifyLogin() {
console.log("inside spotifyLogin, opening popup")
let popup = window.open(`https://accounts.spotify.com/authorize?client_id=5a576333cfb1417fbffbfa3931b00478&response_type=token&redirect_uri=https://codepen.io/martin-barker/pen/YzPwXaz&show_dialog=true&scope=playlist-modify-public`, 'Login with Spotify', 'width=800,height=600')
}
//get url from popup and parse access token????
window.spotifyCallback = (payload) => {
console.log("inside window? ") //this line never appears in console
popup.close()
fetch('https://api.spotify.com/v1/me', {
headers: { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试加载测试网页(在我的服务器中).页面是:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<iframe width="420" height="315" src="http://www.youtube.com/embed/XGSy3_Czz8k?autoplay=1"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是webView没有加载页面.甚至没有onProgressChanged在%40-50之后调用
此外,从url加载js脚本的所有站点都会出现此问题.包括youtube,fb等.
WebConsole: XMLHttpRequest cannot load https://googleads.g.doubleclick.net/pagead/id. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.youtube.com' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
在这里我的设置
FrameLayout contentFrame = (FrameLayout) findViewById(R.id.ContentFrame);
WebView mWebView = new WebView(this);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
mWebView.loadUrl("http://ozgur.dk/browser.html");
contentFrame.removeAllViews();
contentFrame.addView(mWebView);
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/ContentFrame"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Run Code Online (Sandbox Code Playgroud) 通过添加以下内容,我可以设置请求标头以显示Content-Disposition:“ Access-Control-Expose-Headers”:“ Content-Disposition”
我可以看到响应,但是响应对象不包含Content-Disposition。 点击此处查看详细屏幕截图
我有什么办法可以获取该价值?
axios版本:0.15.2环境:节点v6.9.4,chrome 54,Windows 7