Last active
August 29, 2015 14:18
-
-
Save ishankhare07/e8288f9bf381a378133c to your computer and use it in GitHub Desktop.
python socket GET request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
class Get: | |
""" | |
this class makes get request to httpbin | |
""" | |
def __init__(self): | |
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,0) | |
self.request = ("GET /get HTTP/1.1\n" | |
"Host: httpbin.org\n" | |
"User-Agent:Mozilla 5.0\n\n" | |
) | |
def make_request(self): | |
self.s.connect(('httpbin.org',80)) | |
self.s.send(self.request.encode('utf-8')) | |
self.response = self.s.recv(4096) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment