def __init__(self, url, headers: dict): HttpTransfer.__init__(self) self.https = False self.urlparse = p = urlparse(url) port = 80 if p.scheme == "https": port = 443 self.https = True hostname = p.netloc if ":" in p.netloc: try: hostname, port = p.netloc.split(":") port = int(port) except: hostname = p.netloc port = 80 self.hostname = hostname self.port = port self.command = 'GET' self.path = p.path + "?" + p.query self.request_version = 1.1 # self.urlparse = None self.netloc = "{}://{}{}".format(p.scheme, p.netloc, p.path) self.params = paramToDict(p.query, place=PLACE.GET) self._header = headers self._body = b''
def __init__(self, resp: requests.Response): HttpTransfer.__init__(self) self.response_version = 1.1 self.status = resp.status_code self.reason = resp.reason self._body = resp.content self._headers = resp.headers self.decoding = chardet.detect(self._body)['encoding'] # 探测当前的编码
def __init__(self, resp: requests.Response): HttpTransfer.__init__(self) self.response_version = 1.1 self.status = resp.status_code self.reason = resp.reason self._body = resp.content self._headers = resp.headers self.decoding = chardet.detect(self._body)['encoding'] # 探测当前的编码 self.parse = urlparse(resp.url) self._url = "{}://{}{}".format(self.parse.scheme, self.parse.netloc, self.parse.path) if self.parse.query: self._url += "?" + self.parse.query
def __init__(self, url, headers: dict, method='GET', data={}): HttpTransfer.__init__(self) self.https = False self.urlparse = p = urlparse(url) port = 80 if p.scheme == "https": port = 443 self.https = True hostname = p.netloc if ":" in p.netloc: try: hostname, port = p.netloc.split(":") port = int(port) except: hostname = p.netloc port = 80 self.hostname = hostname self.port = port self.command = 'GET' if method == 'GET' else method self._body = b'' if self.command == 'POST': self.post_hint = POST_HINT.NORMAL self._body = '' for k, v in data.items(): self._body += "{}={};".format(k, v) self._body = self._body.encode() self.post_hint = POST_HINT.NORMAL self.post_data = data self.path = p.path if p.query: self.path = p.path + "?" + p.query self.request_version = 1.1 # self.urlparse = None self.netloc = "{}://{}{}".format(p.scheme, p.netloc, p.path) self.tld = get_fld(self.netloc, fix_protocol=True, fail_silently=True) self.params = paramToDict(p.query, place=PLACE.GET) self.cookies = None if "cookie" in headers or "Cookie" in headers: self.cookies = paramToDict(headers.get("cookie", headers.get("Cookie")), place=PLACE.COOKIE) self._headers = headers