Thursday, 22 August 2013

Split an HTTP response in python

Split an HTTP response in python

I'm trying to split an HTTP response data using CRLF but so far it doesn't
seem to work.
data = s.recv(MAX_DATA_RECV)
response_content=data.split("\r\n")
It just displays the second line(date and time) when I try
print response_content[1]
I've tried \n\n too but it results in the same output. I'm trying to
obtain the raw HTTP data. Can anyone tell me whats going wrong?
print repr(data) return the following. I believe it shows \r\n\r\n here.
I'll try that.
'HTTP/1.1 200 OK\r\nDate: Thu, 22 Aug 2013 19:12:06 GMT\r\nServer:
Apache/2.2.22 (Ubuntu)\r\nX-Powered-By: PHP/5.3.10-1ubuntu3.7\r\nExpires:
Thu, 19 Nov 1981 08:52:00 GMT\r\nCache-Control: no-store, no-cache,
must-revalidate, post-check=0, pre-check=0\r\nPragma: no-cache\r\nVary:
Accept-Encoding\r\nContent-Encoding: gzip\r\nContent-Length:
189\r\nKeep-Alive: timeout=5, max=100\r\nConnection:
Keep-Alive\r\nContent-Type:
text/html\r\n\r\n\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x8d\x90;\x0e\xc3
\x10Dk\xe7\x14T\xa1\x0b\x92k\xec&M\x9a(\x96\x9c\x0b\x80\xbd\x11H\xfc\x84\xd7\x91}\xfb\xf0q\xe3.\rh\x96y\xb3\x1a\xb8Bk\xfaK\xc3\x15\x889\xdd\rG\x8d\x06\xfa\x07\x18\xe3\xc93\x92\x01"D\xc1Y\x1d\'#;\x9c\\\xfay/\xc4\xc7GK\x9c\xb0\xd0Q\x84\x05\xb3\xa4\xc4\x02*?w\xc3k|\x131\xa1\xf6\xae\xbe\xde\x82\n4cMYqur\t\\\xbb\xb0"\xc1=\x94\x88\r\xa5\xdf\xe8\x91\x98O\xdasV,\x85\xbb{7\t\xfc\x0bl\xcf\xe4\xc9\xbe\xac\xd2j\xa4\xe4+\xcc\x9a\xe4Xe)\xc4r\x85J\xb0\xda2\xb5.\xff\xf4\x03\xc3\x8bU\x95/\x01\x00\x00'

No comments:

Post a Comment