0

I have the following code where a POST request is sent to a http server with a JSON request body. The debug prints out 2 requests, showing that the request body is sent as a separate request.

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()

enter image description here

Nice Books
  • 1,675
  • 2
  • 17
  • 21

0 Answers0