Reputation: 267
So I was reading about these partial GET requests that would make a server timeout the connection after a while on this request. How would send a partial GET request?..
import socket, sys
host = sys.argv[1]
request = "GET / HTTP/1.1\nHost: "+host+"\n\nUser-Agent:Mozilla 5.0\n" #How could I make this into a partial request?
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, 80))
s.sendto(request, (host, 80))
response = s.recv(1024)
How would I do this?
Upvotes: 4
Views: 3424
Reputation: 369454
The HTTP headers ends too early. (\n\n
should come after headers, before the contents)
import socket, sys
host = sys.argv[1]
request = "GET / HTTP/1.1\nHost: "+host+"\nUser-Agent:Mozilla 5.0\n\n"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, 80))
s.send(request)
response = s.recv(1024)
If you mean partial content retrieval, you can speicfy Range
header:
"GET / HTTP/1.1\nHost: "+host+"\nUser-Agent:Mozilla 5.0\rRange: bytes=0-999\n\n"
NOTE
It should be \r\n
not \n
as line end, even if most (but not all) servers accept \n
too.
Upvotes: 0
Reputation: 123639
I think you confuse partial and incomplete requests:
\r\n\r\n
and not a single \n
). Other ways are just a TCP connect without sending any data or doing a POST request with a content-length and then not sending as much data as specified in the request header.Upvotes: 1