从 libcurl 计算 HTTP POST 的 Content-MD5
我正在使用 libcurl 来构建 HTTP POST,使用 structcurl_httppost 和curl_formadd 等。
我需要能够计算将要发布的整个内容的 MD5 哈希值,包括边界标记等。然后 MD5需要作为 HTTP 标头“Content-MD5”上传。
有没有办法从curl API获取原始帖子内容,以便我可以在发布之前对其计算MD5?或者,curl 中是否已经有一种机制可以简单地计算 MD5 并在内部设置标头?
struct curl_httppost* list = NULL;
struct curl_httppost* last = NULL;
curl_formadd (&list, &last,
CURLFORM_COPYNAME, pFieldName,
CURLFORM_BUFFER, pFieldFilename,
CURLFORM_BUFFERPTR, pFileContents,
CURLFORM_BUFFERLENGTH, lenFileContents,
CURLFORM_END);
curl_easy_setopt(session, CURLOPT_URL, url);
curl_easy_setopt(session, CURLOPT_HTTPPOST, list);
谢谢。
I am using libcurl to build up an HTTP POST, using struct curl_httppost with curl_formadd, etc.
I need to be able to compute an MD5 hash value for the entire contents as they will be posted, including the boundary markers, etc. That MD5 then needs to be uploaded as the HTTP header "Content-MD5".
Is there a way to get the raw post content from the curl API so that I can compute an MD5 on it before it is posted? Or, is there already a mechanism within curl to simply compute the MD5 and set the header internally?
struct curl_httppost* list = NULL;
struct curl_httppost* last = NULL;
curl_formadd (&list, &last,
CURLFORM_COPYNAME, pFieldName,
CURLFORM_BUFFER, pFieldFilename,
CURLFORM_BUFFERPTR, pFileContents,
CURLFORM_BUFFERLENGTH, lenFileContents,
CURLFORM_END);
curl_easy_setopt(session, CURLOPT_URL, url);
curl_easy_setopt(session, CURLOPT_HTTPPOST, list);
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然答案是通过curl_formget检索内容。从那里,我可以计算 MD5 哈希值并设置标头。
http://curl.haxx.se/libcurl/c/curl_formget.html
Apparently the answer is to retrieve the content through curl_formget. From there, I can compute the MD5 hash and set the header.
http://curl.haxx.se/libcurl/c/curl_formget.html