如何使用wininet在我的vc ++应用程序中发送zip文件 [英] how to send a zip file using wininet in my vc++ application
问题描述
我可以通过这两个变量存储头来发送一个txt文件...
I was able to send a txt file by having these 2 variables storing header...
static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858";
sprintf(frmdata,"-----------------------------7d82751e2bc0858\r\nContent-Disposition: form-data; name=\"uploaded_file\";filename=\"%s\"\r\nContent-Type:application/octet-stream\r\n\r\n",temp_upload_data->file_name);
我将txt文件数据添加到frmdata变量的末尾。 。
和我使用此函数发送请求
I am adding txt file data to frmdata variable at its end.i am opening txt file in read mode. and i am using this function to send request
sent= HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
通过这个我可以上传一个txt文件..
现在我想上传一个zip文件...
我需要一些帮助如何做到这一点...
thnx提前...
by this i am able to upload a txt file.. now i want to upload a zip file... I need some help on how to do this... thnx in advance...
推荐答案
这些代码适用于我
首页标题部分:
This some codes work for me
First the header parts:
static char hdrs[] = "Content-Type: multipart/form-data; boundary=AaB03x";
static char head[] = "--AaB03x\r\n"
"Content-Disposition: form-data; name=\"userfile\"; filename=\"test.bin\"\r\n"
"Content-Type: application/octet-stream\r\n"
"\r\n";
static char tail[] = "\r\n"
"--AaB03x--\r\n";
和下面的主要代码...最常见的是发送
和 tail []
您发送(写)
数据。 $ b我已经从 InternetOpen()
到 HttpOpenRequest()
删除错误检查和代码, code> WinINet 示例:
and main codes below...most is between sending the head[]
and tail[]
you send(write)
the data.
I had removed error checking and codes from InternetOpen()
to HttpOpenRequest()
for they were known in other WinINet
examples:
...call InternetOpen...
...call InternetConnect...
...call HttpOpenRequest...
// your binary data
char data[] = "\x01\x02\x03\x04.....
DWORD dataSize = ...
// prepare headers
HttpAddRequestHeaders(hRequest,
hdrs, -1,
HTTP_ADDREQ_FLAG_REPLACE |
HTTP_ADDREQ_FLAG_ADD);
// send the specified request to the HTTP server and allows chunked transfers
INTERNET_BUFFERS bufferIn;
memset(&bufferIn, 0, sizeof(INTERNET_BUFFERS));
bufferIn.dwStructSize = sizeof(INTERNET_BUFFERS);
bufferIn.dwBufferTotal = strlen(head) + dataSize + strlen(tail);
HttpSendRequestEx(hRequest, &bufferIn, NULL, HSR_INITIATE, 0);
// write data to an open Internet file
// 1. stream header
InternetWriteFile(hRequest, (const void*)head, strlen(head), &bytesWritten);
// 2. stream contents (binary data)
InternetWriteFile(hRequest, (const void*)data, dataSize, &bytesWritten);
// or a while loop for call InternetWriteFile every 1024 bytes...
// 3. stream tailer
InternetWriteFile(hRequest, (const void*)tail, strlen(tail), &bytesWritten);
// end a HTTP request (initiated by HttpSendRequestEx)
HttpEndRequest(hRequest, NULL, HSR_INITIATE, 0);
关于要获取'userfile'的php代码,请参考php的示例示例#2验证文件上传
About the php codes to get 'userfile', please ref to php's example Example #2 Validating file uploads
希望它有助于
这篇关于如何使用wininet在我的vc ++应用程序中发送zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!