0

我已经在 AWS EC2 实例上部署了一个烧瓶应用程序作为http. 现在,我正在尝试使用运行在localhost. 我收到以下错误 -

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://X.X.X.X/login. (Reason: CORS request did not succeed). Status code: (null).

反应应用

login = (event) => {
    fetch("http://3.18.107.201/login", {
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "body": JSON.stringify({
                userId: this.state.loginParams.user_id,
                userPassword: this.state.loginParams.user_password
            })
        }).then(res => {
            if (res.status == 200) {
                res.json().then(data => {
                    console.log(data);
                }
            }
        }
    }
}

烧瓶应用

from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin


app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/*": {"origins": "*"}})


@app.route('/login', methods=['post'])
def login():

    data = request.get_json()
    ...
    return jsonify(response), 200

我尝试了其他帖子中也提到的其他事情,但似乎没有任何效果。

4

0 回答 0