简体   繁体   中英

How to pass data and header both in axios get request?

 let res = await axios({
    method: 'get',
    url: url1,
    params: params,  
   /*  headers: { 'Authorization': "Bearer `${token}`" } */
  });

On passing the headers, I'm getting CORS error (token is string)

This is the code of backend (flask)

 app = Flask(__name__)
    app.config.update(
        TESTING=True,
        SECRET_KEY="super secret key",
        JWT_ACCESS_TOKEN_EXPIRES=datetime.timedelta(minutes=30),
        CORS_HEADERS='application/json'            
        )
   app.config['CORS_HEADERS'] = 'Content-Type'            
   api = Api(app)
   login_manager = LoginManager()
   login_manager.init_app(app)
   jwt = JWTManager(app)
   CORS(app, support_credentials=True)
   Base.metadata.create_all(engine)
            

  

You are trying to pass some object (JSON?) in a GET request. You should use a POST request instead:

 let res = await axios({
    method: 'post',
    url: url1,
    params: params,  
    headers: { 'Authorization': "Bearer `${token}`" }
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM