Python 节点服务器没有收到我发送给他的JSON文件
我正在尝试使用python向我的express服务器发送post请求,以下是我的代码:Python 节点服务器没有收到我发送给他的JSON文件,python,express,Python,Express,我正在尝试使用python向我的express服务器发送post请求,以下是我的代码: import requests print("started"); URL = "http://localhost:5000/api/chat" PARAMS = {'ID':"99","otherID":"87",'chat':[{"senderName":"tom","text":"helloworld"}]} r = requests.post(url = URL, data = PARAMS)
import requests
print("started");
URL = "http://localhost:5000/api/chat"
PARAMS = {'ID':"99","otherID":"87",'chat':[{"senderName":"tom","text":"helloworld"}]}
r = requests.post(url = URL, data = PARAMS)
pastebin_url = r.text
print("The pastebin URL is:%s"%pastebin_url)
但是当我收到调用时,我在节点服务器上得到一个空对象,我是否遗漏了什么?
(对于postman,它可以正常工作,因此不是服务器)通常,请求库根据用于发出请求的参数在请求类型上进行区分。这意味着,如果您打算发布一篇JSON文章,那么应该像这样使用
JSON
param:
response = requests.post(url=URL, json=PARAMS)
这样做的目的是设置附带的标题,这就是为什么当您的express服务器尝试解析它时,它返回为空