亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過CORS政策允許任何內容

通過CORS政策允許任何內容

慕后森 2019-10-25 13:16:32
如何禁用cors?由于某種原因,我對允許的來源和標頭進行了通配符轉換,但我的ajax請求仍然抱怨我的CORS策略不允許該來源。我的應用程序控制器:class ApplicationController < ActionController::Base  protect_from_forgery  before_filter :current_user, :cors_preflight_check  after_filter :cors_set_access_control_headers# For all responses in this controller, return the CORS access control headers.def cors_set_access_control_headers  headers['Access-Control-Allow-Origin'] = '*'  headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'  headers['Access-Control-Allow-Headers'] = '*'  headers['Access-Control-Max-Age'] = "1728000"end# If this is a preflight OPTIONS request, then short-circuit the# request, return only the necessary headers and return an empty# text/plain.def cors_preflight_check  if request.method == :options    headers['Access-Control-Allow-Origin'] = '*'    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'    headers['Access-Control-Allow-Headers'] = '*'    headers['Access-Control-Max-Age'] = '1728000'    render :text => '', :content_type => 'text/plain'  endend  private  # get the user currently logged in  def current_user    @current_user ||= User.find(session[:user_id]) if session[:user_id]  end  helper_method :current_userend路線:  match "*all" => "application#cors_preflight_check", :constraints => { :method => "OPTIONS" }  match "/alert" => "alerts#create"  match "/alerts" => "alerts#get"  match "/login" => "sessions#create"  match "/logout" => "sessions#destroy"  match "/register" => "users#create"編輯 - -我也嘗試過:   config.middleware.use Rack::Cors do      allow do        origins '*'        resource '*',             :headers => :any,             :methods => [:get, :post, :delete, :put, :options]      end    end在application.rb中-編輯2 ---問題是我認為Chrome擴展程序可能不支持CORS。如何繞過CORS獲取信息?我應該如何應對飛行前檢查?
查看完整描述

3 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

對于使用rails-api的公共API,我有相同的要求。


我也將頭設置在before過濾器中??雌饋硐襁@樣:


headers['Access-Control-Allow-Origin'] = '*'

headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'

headers['Access-Control-Request-Method'] = '*'

headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'

看來您錯過了Access-Control-Request-Method標頭。


查看完整回答
反對 回復 2019-10-25
  • 3 回答
  • 0 關注
  • 1171 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號