Questo è il mio codice:
@app.route('/hello', methods=["POST"])
def hello():
resp = make_response()
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
Tuttavia, quando effettuo una richiesta dal browser al mio server ottengo questo errore:
XMLHttpRequest cannot load http://localhost:5000/hello.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Ho anche provato questo approccio, impostando le intestazioni di risposta "dopo" la richiesta:
@app.after_request
def add_header(response):
response.headers['Access-Control-Allow-Origin'] = '*'
return response
Niente da fare. Ho fatto lo stesso errore. C'è un modo per impostare solo le intestazioni di risposta nella funzione route? Qualcosa di simile sarebbe l'ideale:
@app.route('/hello', methods=["POST"])
def hello(response): # is this a thing??
response.headers['Access-Control-Allow-Origin'] = '*'
return response
ma non riesco a trovare comunque per farlo. Per favore aiuto.
MODIFICARE
se arriccio l'URL con una richiesta POST in questo modo:
curl -iX POST http://localhost:5000/hello
Ottengo questa risposta:
HTTP/1.0 500 INTERNAL SERVER ERROR
Content-Type: text/html
Content-Length: 291
Server: Werkzeug/0.9.6 Python/2.7.6
Date: Tue, 16 Sep 2014 03:58:42 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>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.</p>
Qualche idea?