pycurl equivalent of “curl --data-binary”

て烟熏妆下的殇ゞ 提交于 2019-12-04 05:09:48
Jon Clements

The requests library is meant to keep things like this simple:

import requests
r = requests.post('http://server/myapp/method', data={'aaa': 'bbb'})

Or depending on how the receiving end expects data:

import requests
r = requests.post('http://server/myapp/method',
    data=file('binary_data_file.bin','rb').read())

From libcurl, setopt(...) try this option:

CURLOPT_POSTFIELDSIZE

If you want to post data to the server without letting libcurl do a strlen() to measure the data size, this option must be used. When this option is used you can post fully binary data, which otherwise is likely to fail. If this size is set to -1, the library will use strlen() to get the size.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPOSTFIELDSIZE

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!