access-control-allow-origin

“No 'Access-Control-Allow-Origin' header is present on the requested resource” in django

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am newbie to django and using it as back end for an application that creates users. In front end the code for posting the user name is : var xobj = new XMLHttpRequest (); xobj . overrideMimeType ( "application/json" ); xobj . open ( 'POST' , "http://www.local:8000/create_user/" , true ); xobj . setRequestHeader ( "Access-Control-Allow-Origin" , "*" ); xobj . onreadystatechange = function () { if ( xobj . readyState == 4 && xobj . status == "200" ) { console . log ( xobj . responseText ); } } xobj . send ( json ); On back end the

AngularJS : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: here is my code : angular.module('option') .factory('optionListService', ['$resource', function($resource) { return $resource(HOST+'option/action/:id', {}, { 'get': {method:'GET'}, 'save': {method:'POST'}, 'query': {method:'GET', isArray:true}, 'remove': {method:'DELETE'}, 'delete': {method:'DELETE'} }); }]); and this work for GET requests and not for POST ! I'm using Apache as a server and configured it with : Order Allow,Deny Allow from all Header set Access-Control-Allow-Origin "*" and in my angularjs I include in config of module app:

Cross-Origin Request Blocked

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I've got this Go http handler that stores some POST content into the datastore and retrieves some other info in response. On the back-end I use: func handleMessageQueue(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") if r.Method == "POST" { c := appengine.NewContext(r) body, _ := ioutil.ReadAll(r.Body) auth := string(body[:]) r.Body.Close() q := datastore.NewQuery("Message").Order("-Date") var msg []Message key, err := q.GetAll(c, &msg) if err != nil { c.Errorf("fetching msg: %v", err) return }

NGINX 'Access-Control-Allow-Origin' header contains multiple values

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an NGINX server with PHP (let's assume a hostname of http://myserver.com ). I have a PHP script that I'm accessing via XHR from a web page on my localhost. I'm using it as a GeoIP server similar to freegeoip.net. I'm trying to lock down XHR to specific domains. Here's my config setup: location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param GEOIP_COUNTRY_CODE $geoip2_data_country_code; fastcgi

CORS header 'Access-Control-Allow-Origin' missing

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm calling this function from my asp.net form and getting following error on firebug console while calling ajax. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://anotherdomain/test.json . (Reason: CORS header 'Access-Control-Allow-Origin' missing). var url= 'http://anotherdomain/test.json'; $.ajax({ url: url, crossOrigin: true, type: 'GET', xhrFields: { withCredentials: true }, accept: 'application/json' }).done(function (data) { alert(data); }).fail(function (xhr, textStatus, error) { var

HTTP GET to amazon aws from jquery or XMLHttpRequest fails with Origin is not allowed by Access-Control-Allow-Origin

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Having some bad luck with getting amazon AWS security token from jQuery or XMLHttpRequest. When I send a HTTP GET from jQuery or XmlHttpRequest, I get "Origin http:// MY_IP is not allowed by Access-Control-Allow-Origin.", but if I paste the same URL in my browser, it all goes fine. My code: var url_ = "https://sts.amazonaws.com/?Action=GetSessionToken" + "&DurationSeconds=3600" + "&AWSAccessKeyId=" + AccessKeyId + "&Version=2011-06-15" + "&Timestamp=" + encode(timestamp) + "&Signature=" + encode(hash) + "&SignatureVersion=2&SignatureMethod

Angular 6 - No 'Access-Control-Allow-Origin' header is present on the requested resource

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an Angular 6 project, which has a service with is pointing to a server.js Angular is on port: 4200 and Server.js is on port: 3000. When I point the service to http://localhost:3000/api/posts (Server.js location), I'm getting this error: Failed to load http://localhost:3000/api/posts: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. Here is the server.js code: // Get dependencies const express = require('express'); const path = require('path');

CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a setup involving Frontend server (Node.js, domain: localhost:3000) Backend (Django, Ajax, domain: localhost:8000) Browser Browser (webapp) --> Ajax --> Django(Serve ajax POST requests) Now, my problem here is with CORS setup which the webapp uses to make Ajax calls to the backend server. In chrome, I keep getting Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true. doesn't work on firefox either. My Node.js setup is: var allowCrossDomain = function(req, res, next) { res.header('Access-Control-Allow-Origin

Ajax 跨域请求 Access-Control-Allow-Origin 问题小记

匿名 (未验证) 提交于 2019-12-03 00:32:02
前言 在前后端分离的项目中经常会遇到 Ajax 跨域的问题,然而网上大多数教程都是使用 * 通配符放行所有请求。然而这是不对的,没有解决根本问题。 正文 其实放行指定的域名很简单,下面我介绍下 PHP 和 Nginx 的。 PHP $http_origin = isset ( $_SERVER [ 'HTTP_ORIGIN' ] ) ? $_SERVER [ 'HTTP_ORIGIN' ] : '' ; if ( preg_match ( '/domain1.com|domain2.com$/i' , $http_origin ) ) { header ( 'Access-Control-Allow-Origin: ' . $http_origin ) ; } PHP Nginx location / { if ( $http_origin ~ 'domain1.com|domain2.com$' ) { add_header Access - Control - Allow - Origin $http_origin ; } } NGINX Access-Control-Allow-Origin 是不是很简单,直接在代码中使用正则进行匹配。只要你会正则,更严格的匹配模式自然就会了。 下面附上其他模式: 放行所有域名 PHP header ( 'Access-Control

ajax 跨域问题(两种解决办法)

匿名 (未验证) 提交于 2019-12-03 00:27:02
为什么会出现跨域 跨域问题来源于JavaScript的同源策略,即只有 协议+主机名+端口号 (如存在)相同,则允许相互访问。也就是说JavaScript只能访问和操作自己域下的资源,不能访问和操作其他域下的资源。跨域问题是针对JS和ajax的,html本身没有跨域问题,比如a标签、script标签、甚至form标签(可以直接跨域发送数据并接收数据)等 jsopn原理 在js中,我们直接用XMLHttpRequest请求不同域上的数据时,是不可以的。但是,在页面上引入不同域上的js脚本文件却是可以的,jsonp正是利用这个特性来实现的。 比如,有个a.html页面,它里面的代码需要利用ajax获取一个不同域上的json数据,假设这个json数据地址是 http://example.com/data.php ,那么a.html中的代码就可以这样: 我们看到获取数据的地址后面还有一个callback参数,按惯例是用这个参数名,但是你用其他的也一样。当然如果获取数据的jsonp地址页面不是你自己能控制的,就得按照提供数据的那一方的规定格式来操作了。 因为是当做一个js文件来引入的,所以 http://example.com/data.php 返回的必须是一个能执行的js文件,所以这个页面的php代码可能是这样的: 最终那个页面输出的结果是: 所以通过 http://example.com