2

I'm using python 2.6 to create a HTTPS client that can POST XML data. So far it is able to POST to a HTTP server I also wrote. The issue is that when I try to return the status and reason from the response, it isn't correct.

The HTTPS server should return an empty response with a HTTP 202 status. When I use curl to POST to it, it properly returns what I expect. The HTTPS python client gets back a HTTP 200 and a empty reason. It is as if the response object I'm parsing isn't correct or hasn't been created from the correct request.

import httplib

def https_client(client_host, client_port, client_key, client_cert, xml_file, client_path)

    headers = {"Content-type" : "application/xml"}

    http_post = httplib.HTTPSConnection(client_host, client_port, client_key, client_cert)
    http_post.request("POST", "/" + client_path, xml_file, headers)
    response1 = http_post.getresponse()
    print response1.status, response1.reason

The console returns:

200

The server is getting the POST and like I mentioned before I can get a 202 status and Accepted reason back when using curl. I've seen something about read the response and/or closing the connection, but I've not found an example of needing to do that.

luker3
  • 21
  • 1

1 Answers1

0

The true issue was with the server not the client. It was discovered that the connection was terminating before the client expected. This was due to the server not reading the body of the incoming request before it send the response. I don't need to read it for any reason, so I neglected to do so.

def do_POST(self):
    body = self.rfile.read("0")
    self.send_response(200)
    self.send_header("Content-type", "application/xml")
    self.end_headers()
luker3
  • 21
  • 1