我嘗試使用Axios公司做出POST到燒瓶中,服務器:愛可信,POST請求燒瓶
var config = { headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'}
}
axios.post("http://127.0.0.1:5000/test",
{ label : "Test" , text : "Test"} , config
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
現在燒瓶中的一部分
...
data = request.get_json(silent=True)
item = {'label': data.get('label'), 'text': data.get('text')}
print item
...
不過,我會結束與以下錯誤:
XMLHttpRequest無法加載http://127.0.0.1:5000/test。對預檢請求的響應不會通過訪問控制檢查:請求的資源上不存在「訪問控制 - 允許來源」標頭。因此不允許訪問原產地'http://localhost:3000'。
爲什麼?我按照建議設置標題。
這裏的解決方案
from flask_cors import CORS, cross_origin app = Flask(__name__) cors = CORS(app, resources={r"/YOURAPP/*": {"origins": "*"}})