I have been trying for many days now, so here I am finally asking, may be dumb question for most of the experts.
I am using PyUnit for API testing of my application.
The application (to be tested) is deployed on one of the local servers over here. The application prevents hackers from doing malicious activities. So I am accessing any website (protected by this application) through this application. e.g. http://my-security-app/stackoverflow/login , http://my-security-app/website-to-be-protected etc.
Almost the whole framework is running around Urllib and Urllib2.
Scenario:- I need to send a request without 'Host' header or a request with 'Host123' as a header name instead of original, using python.
I have been trying below mentioned code. But its not working for me.
"Test failed because of an exception: [Errno 9] Bad file descriptor"
host = "12.1.3.16"
with closing(socket.create_connection((host, 80))) as s:
# send request without Host header
s.sendall(b"GET /mywebsite/administrator/ HTTP/1.1\r\n" +
#"Host12:{}\r\n".format(host).encode('ascii', 'strict') +
b"Connection: close\r\n\r\n")
Any help would be deeply appreciated.
Thanks in advance!
socketdirectly to send invalid http request. Here's code example