def post_multipart(url, fields, files):
parts = urlparse.urlparse(url)
scheme = parts[0]
host = parts[1]
selector = parts[2]
content_type, body = encode_multipart_formdata(fields, files)
if scheme == 'http':
h = httplib.HTTP(host)
elif scheme == 'https':
h = httplib.HTTPS(host)
else:
raise ValueError('unknown scheme: ' + scheme)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()
评论列表
文章目录