我有以下代码,其中POST请求被发送到具有JSON请求主体的http服务器。调试打印出2个请求,表明请求正文是作为单独的请求发送的。
import http.client
import json
if __name__ == "__main__":
connexion = http.client.HTTPConnection('localhost',27015)
headers = {'Content-type': 'application/json','Accept': 'application/json'}
dataSent = {'coup': 'e2e4'}
json_dataSent = json.dumps(dataSent)
connexion.set_debuglevel(1)
connexion.request('POST','/faireCoup',json_dataSent,headers)
reponse = connexion.getresponse()
print(reponse.read().decode())
connexion.close()