如何通过HTTP发送二进制发布数据?

esa*_*sac 2 python binary post http

我已经从文件中读取了二进制数据.我在网上看到的大多数例子直接链接到文件,并上传整个文件.我正在寻找如何通过python中的HTTP POST从其他来源上传我已经拥有的二进制数据.

Mat*_*hen 6

或者:

req = urllib2.Request("http://example.com", data, {'Content-Type': 'application/octet-stream'})
urllib2.urlopen(req)
Run Code Online (Sandbox Code Playgroud)

这也显示了如何指定数据的Content-Type.