angularアプリからflaskサーバーへのPOSTリクエストを行うと、次のCORSエラーが発生します。
No 'Access-Control-Allow-Origin' header is present on the requested resource.
フラスコサーバー:
from flask import Flask, request
from flask.ext.cors import CORS
app = Flask(__name__)
cors = CORS(app)
@app.route('/testPost', methods=['POST'])
def testPost():
phone = request.values.get('phone')
return phone
if __name__ == '__main__':
app.run(debug=True)
さまざまな応答ヘッダーの組み合わせを試しましたが、うまくいきませんでした。飛行前の OPTIONS リクエストは、次のヘッダーで 200 ok を返します。
応答:
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Allow: POST, OPTIONS
Access-Control-Allow-Origin: http://localhost:7000
Access-Control-Allow-Headers: accept, content-type
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
Content-Length: 0
Server: Werkzeug/0.11.3 Python/2.7.11
Date: Wed, 18 May 2016 00:58:10 GMT
リクエスト:
OPTIONS /testPost HTTP/1.1
Host: localhost:5000
Connection: keep-alive
Cache-Control: max-age=0
Access-Control-Request-Method: POST
Origin: http://localhost:7000
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: http://localhost:7000/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8