def httpraw(self, url, raw, proxy=None, cookcookie=True, location=True): https, host, port, path = self._get_urlinfo(url) raw = StringIO(raw.lstrip()) requestline = raw.readline().rstrip() words = requestline.split() if len(words) == 3: command, _, _ = words elif len(words) == 2: command, _ = words else: raise Exception('http raw parse error') headers = parse_header(raw) rawbody = '' content_type = headers.get('Content-Type', "") # Content-Type: application/x-www-form-urlencoded # Content-Type: multipart/form-data if content_type.startswith('application/x-www-form-urlencoded'): while 1: line = raw.readline() if line == '': rawbody = rawbody[:-2] break rawbody += line.rstrip() + '\r\n' if content_type.startswith('multipart/form-data'): while 1: line = raw.readline() if line == '': break if line[:2] == "--": if rawbody != "" and rawbody[-2:] != '\r\n': rawbody = rawbody[:-1] + '\r\n' rawbody += line.rstrip() + '\r\n' elif line[:8].lower() == 'content-': rawbody += line.rstrip() + '\r\n' line = raw.readline() if line[:8].lower() == 'content-': rawbody += line.rstrip() + '\r\n' raw.readline() rawbody += '\r\n' else: rawbody += line headers['Host'] = host headers['Content-Length'] = str(len(rawbody)) return self._http(url, post=rawbody, headers=headers, method=command, proxy=proxy, cookcookie=cookcookie, location=location)