我不明白爲什麼這不起作用。在服務器上,我有這樣的:jQuery POST:將Content-Type設置爲文本/純文本
@app.route('/message', methods=['POST'])
def print_post():
if request.headers['Content-Type'] == 'text/plain':
logging.warning(request.data)
return "Text Message: " + request.data
else:
logging.warning('didnt work')
return 'Unsupported Media Type'
我送通過瀏覽器這個請求:
$.ajax({
type: "POST",
url: "https://localhost:8090/message",
data: 'this is a message'
contentType: 'test/plain'
})
但我不斷收到錯誤Uncaught SyntaxError: Unexpected identifier
我在做什麼錯?
是這個錯字逗號後數據丟失':「這是一個message''和'的contentType:」測試/平原'這應該是'文本/平原'? –
這類問題的問題是,標題是一個很好的問題,但是在問題的主體中陳述的實際問題是對OP的尷尬..所以如何投票?上或下?由於問題本身的重要性,我說**起來**,即使這裏的問題是一個錯字。 – vsync