我一直在尝试从React应用程序向Flask应用程序发送一个简单的数组,但是对于应用程序网络我还是很陌生。
烧瓶(整个应用程序):
from flask import Flask, request, jsonify
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['GET', 'POST'])
def parse_request():
data = request.data
if __name__ == "__main__":
app.run()
两个应用程序都运行时转到本地主机:5000,我得到:
Internal Server Error
The server encountered an internal error and was unable to
complete
your request. Either the server is overloaded or there is an error
in the application.
反应:
sendTopArtists() {
fetch("http://localhost:5000", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(artistList)
})
.then(function(response){
return response.json();
})
.then(function(artistList){
console.log(artistList)
});
}
如何将数组从运行在localhost:3000的React应用程序发送到运行在localhost:5000的Flask应用程序?
谢谢!