我试图通过连接到Flask内置的RESTful API来使用JavaScript进行授权.但是,当我发出请求时,我收到以下错误:
XMLHttpRequest无法加载http:// myApiUrl/login.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许原点'null'访问.
我知道API或远程资源必须设置标题,但为什么在我通过Chrome扩展程序Postman发出请求时它可以正常工作?
这是请求代码:
$.ajax({
type: "POST",
dataType: 'text',
url: api,
username: 'user',
password: 'pass',
crossDomain : true,
xhrFields: {
withCredentials: true
}
})
.done(function( data ) {
console.log("done");
})
.fail( function(xhr, textStatus, errorThrown) {
alert(xhr.responseText);
alert(textStatus);
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试从HP Alm的REST API中获取一些数据.它适用于小卷曲脚本 - 我得到了我的数据.
现在使用JavaScript,fetch和ES6(或多或少)似乎是一个更大的问题.我一直收到此错误消息:
无法加载Fetch API.对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http://127.0.0.1:3000 "访问.响应具有HTTP状态代码501.如果不透明响应满足您的需要,请将请求的模式设置为"no-cors"以获取禁用CORS的资源.
我知道这是因为我试图从我的localhost中获取该数据,解决方案应该使用CORS.现在我以为我确实这样做了,但不管怎么说它要么忽略我在标题中写的内容,要么问题是别的什么?
那么,是否存在实施问题?我做错了吗?遗憾的是我无法检查服务器日志.我真的有点卡在这里.
function performSignIn() {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
headers.append('Access-Control-Allow-Origin', 'http://localhost:3000');
headers.append('Access-Control-Allow-Credentials', 'true');
headers.append('GET', 'POST', 'OPTIONS');
headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password));
fetch(sign_in, {
//mode: 'no-cors',
credentials: 'include',
method: 'POST',
headers: headers
})
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.log('Authorization failed : ' + error.message));
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Chrome.我也尝试使用Chrome CORS插件,但后来我收到另一条错误消息:
当请求的凭据模式为"include"时,响应中"Access-Control-Allow-Origin"标头的值不能是通配符"*".因此,不允许来源" http://127.0.0.1:3000 "访问.XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制.
我真的不明白我应该如何做这项工作:
var requestURL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=AIzaSyAW4CQp3KxwYkrHFZERfcGSl--rFce4tNw';
console.log(requestURL);
$.getJSON( requestURL, function( data ) {
// data
console.log(data);
});
Run Code Online (Sandbox Code Playgroud)
和我的HTML文件:
<body>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script src="main.js" charset="utf-8"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
我总是在请求的资源上出现No'Access-Control-Allow-Origin'标头.消息...即使我在浏览器中访问https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=AIzaSyAW4CQp3KxwYkrHFZERfcGSl--rFce4tNw,我也会收到正确的JSON.
我认为CORS可以帮助我.我不懂CORS.请问,任何人都可以用简单的术语帮助我吗?我应该改变什么才能使这项工作?
谢谢
与URL称为代理//192.168.xx.xx:8080 / 3hyw7hwoajn21 / HLSPlaylist.m3u8 HTTP 调用代理与URL 的http://192.168.xx.xx:8080 / 3hyw7hwoajn21 / HLS_540_v4.m3u8 调用与URL代理HTTP:// 192.168.xx.xx:8080 / 3hyw7hwoajn21 / HLS_AUDIO_160_K_v4.m3u8 称为URL的代理http://192.168.xx.xx:8080 / 3hyw7hwoajn21 / HLS_224_v4.m3u8
这是Reddit视频的示例:https : //www.reddit.com/r/me_irl/comments/b3vrs4/me_irl
查看JSON,它有一些视频源选项:
"reddit_video": {
"dash_url": "https://v.redd.it/3hyw7hwoajn21/DASHPlaylist.mpd",
"duration": 76,
"fallback_url": "https://v.redd.it/3hyw7hwoajn21/DASH_720?source=fallback",
"height": 720,
"hls_url": "https://v.redd.it/3hyw7hwoajn21/HLSPlaylist.m3u8",
"is_gif": false,
"scrubber_media_url": "https://v.redd.it/3hyw7hwoajn21/DASH_240",
"transcoding_status": "completed",
"width": 1280
}
Run Code Online (Sandbox Code Playgroud)
虽然我似乎可以使其他HLS / m3u8视频与Chromecast SDK配合使用(例如Google自己的示例HLS视频),但似乎无法使所有这些资源都可以使用。
我尝试将流类型设置为“实时”或“缓冲”的https://v.redd.it/3hyw7hwoajn21/HLSPlaylist.m3u8,我尝试将内容类型设置为“ application / x-mpegURL”,并且我对内容URL 为“ application / dash + xml” 的破折号网址https://v.redd.it/3hyw7hwoajn21/DASHPlaylist.mpd尝试了相同的操作,但也无济于事。我发现这个问题似乎暗示了某种可能性?
我还注意到DASH文件中存在单独的视频和音频流(https://v.redd.it/3hyw7hwoajn21/DASH_720和 …
http-live-streaming google-cast chromecast mpeg-dash google-cast-sdk
我是React js的新手我正在尝试简单地动态更改地图并尊重用户输入但是对于特定地点搜索请求此错误会上升
XMLHttpRequest无法加载 https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=undef ... ined&radius = 1000&keyword = fdtbf&key = myapikey.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源' http:// localhost:3000 '访问.
这是我的节点js代码
import express from 'express';
import path from 'path';
import bodyParser from 'body-parser';
//Import To Pord
import api from './routes/api';
import auth from './routes/auth'
import cookieParser from 'cookie-parser';
import {LoginCheck} from './middleware/authCheck';
import cors from 'cors';
//All Webpack Stuff
import webpackConfig from '../../webpack.config.dev';
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware'
import webpackHotMidleware from 'webpack-hot-middleware';
//Server Side Rendering Stuff
import {match, RouterContext } from 'react-router'; …Run Code Online (Sandbox Code Playgroud) 我尝试从 Angular 应用程序拨打电话,但收到以下错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
constructor(private http: Http) {
}
getNearbyRestaurants(lat: number, lng: number){
return this.http.get(this.API_URL+this.API_KEY+`&location=${lat},${lng}`).pipe(
map(result => result)
);
}
}
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?谢谢
javascript ×4
cors ×3
api ×2
google-maps ×2
chromecast ×1
fetch-api ×1
google-api ×1
google-cast ×1
jquery ×1
json ×1
mpeg-dash ×1
node.js ×1
preflight ×1
reactjs ×1
rest ×1