How to send binary post data via HTTP?

前端 未结 2 709
天命终不由人
天命终不由人 2021-01-03 14:00

I already have binary data read from a file. Most of the examples I see online link directly to the file, and upload the whole file. I am looking how to upload the binary da

相关标签:
2条回答
  • 2021-01-03 14:27

    Alternatively:

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

    That also shows how you can specify the Content-Type of the data.

    0 讨论(0)
  • 2021-01-03 14:46

    I'm not sure what online examples you're looking at, but urllib2.urlopen takes the data to post as a chunk of data and not a file at all.

    0 讨论(0)
提交回复
热议问题