1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| ifstream file (filename, ios::in|ios::binary|ios::ate);
size = file.tellg();
file.seekg (0, ios::beg);
buffer = new char [size];
file.read (buffer, size);
file.close();
cPostData = "--AaB03x\r\nContent-Disposition: form-data; name=\"uploadFile\"; filename=\""+cFile+"\"\r\nContent-Transfer-Encoding: binary\r\nContent-Type: application/octet-stream\r\n\r\n"+CString(buffer,size)+"\r\n--AaB03x--";
int leng = cPostData.GetLength();
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0,
leng, 0);
int count = 1023;
if (bResults)
{
for ( int cpt = 0; cpt < leng ; cpt=cpt+count+1)
{
CString toto ;
if (count+cpt > leng)
{
count = leng - cpt;
}
cTemp = CString(cPostData.Mid(cpt,count),count+1);
int longueur = cTemp.GetLength();
LPTSTR lpStr = cTemp.GetBuffer(longueur);
cTemp.ReleaseBuffer();
toto.Format("leng : %i , Count : %i , Longueur cTemp : %i",leng,count,longueur);
OutputDebugString(toto);
bResults = WinHttpWriteData( hRequest, lpStr, longueur, NULL);
}
} |
Partager