好的我明白了。
首先,编写我自己的分块编码函数。
然后使用putrequest(),putheader(),endheaders()和send()代替request()
import http.clientdef chunk_data(data, chunk_size): dl = len(data) ret = "" for i in range(dl // chunk_size): ret += "%srn" % (hex(chunk_size)[2:]) ret += "%srnrn" % (data[i * chunk_size : (i + 1) * chunk_size]) if len(data) % chunk_size != 0: ret += "%srn" % (hex(len(data) % chunk_size)[2:]) ret += "%srn" % (data[-(len(data) % chunk_size):]) ret += "0rnrn" return retconn = http.client.HTTPConnection(host)url = "/some_path"conn.putrequest('POST', url)conn.putheader('Transfer-Encoding', 'chunked')conn.endheaders()conn.send(chunk_data(body, size_per_chunk).enpre('utf-8'))resp = conn.getresponse()print(resp.status, resp.reason)conn.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)