gpt4 book ai didi

jQuery 发布 : setting Content-Type to be text/plain

转载 作者:行者123 更新时间:2023-11-30 23:58:56 25 4
gpt4 key购买 nike

我不明白为什么这不起作用。在服务器上,我有这个:

@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'
})

但我不断收到错误未捕获的语法错误:意外的标识符

我做错了什么?

最佳答案

在 ajax 调用中的 data 属性后面缺少一个逗号,并且 contentType: 'text/plain'

$.ajax({
type: "POST",
url: "https://localhost:8090/message",
data: 'this is a message', // <-- Put comma here
contentType: 'text/plain'
})

关于jQuery 发布 : setting Content-Type to be text/plain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40287282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com