2019-08-13 跨域問題

2019/08/13

  1. 跨域問題
error:Access to XMLHttpRequest at 'http://****' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
warning:Cross-Origin Read Blocking (CORB) blocked cross-origin response http://39.97.170.181/fileTranslate with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
select @ Translate.vue?408e:357
invokeWithErrorHandling @ vue.esm.js?efeb:1863
invoker @ vue.esm.js?efeb:2188
original._wrapper @ vue.esm.js?efeb:7559

解決方法:服務(wù)器端設(shè)置 ↓

from flask import Response
from flask_cors import CORS

class JSONResponse(Response):
    @classmethod
    def force_type(cls, response, environ=None):
        if isinstance(response, (list, dict)):
            response = flask.jsonify(response)
            #response.headers['Access-Control-Allow-Credentials'] = 'true'
            response.headers['Access-Control-Allow-Origin'] = '*'
            #response.headers['Access-Control-Allow-Methods'] = 'OPTIONS,POST'
            #response.headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With'
        # return super(Response, cls).force_type(response, environ)
        return response

CORS(app)
app.response_class = JSONResponse
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容