"Content-Disposition: form-data; name=\"file\"; filename=\""FILE_NAME"\"\r\n"
#include <tchar.h>
#include <Windows.h>
#include <WinInet.h>
#include <fstream>
#include <sstream>
#include <vector>
int _tmain(int argc, _TCHAR* argv[])
{
HINTERNET hInet = ::InternetOpen(
_T("My User Agent")
, INTERNET_OPEN_TYPE_PRECONFIG // get proxy from IE settings
, NULL
, NULL
, 0);
HINTERNET hConn = ::InternetConnect(
hInet
, _T("gtasnp.com")
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0
, NULL
);
LPCTSTR accept[] = {_T("text/html"), NULL};
HINTERNET hReq = ::HttpOpenRequest(
hConn
, _T("POST")
, _T("/upload")
, NULL
, _T("http://gtasnp.com/") // referrer
, accept
, INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_PRAGMA_NOCACHE |
INTERNET_FLAG_RELOAD
, NULL
);
#define FILE_NAME "GTASAsf1.b"
#define BOUNDARY "MySuperPuperUniqueBoundary"
std::ostringstream contentStrm(std::ios_base::out | std::ios_base::binary);
contentStrm
<< "--"BOUNDARY"\r\n"
<< "Content-Disposition: form-data; name=\"file\"; filename=\""FILE_NAME"\"\r\n"
<< "Content-Type: application/octet-stream\r\n\r\n";
contentStrm << std::ifstream(FILE_NAME, std::ios_base::in | std::ios_base::binary).rdbuf();
contentStrm << "\r\n--"BOUNDARY"--\r\n";
std::string content = contentStrm.str();
contentStrm.str(std::string()); // clear memory inside ostringstream
const TCHAR headers[] = _T("Content-Type:multipart/form-data; boundary=")_T(BOUNDARY);
BOOL res = ::HttpSendRequest(
hReq
, headers
, ARRAYSIZE(headers)
, const_cast<char*>(content.c_str())
, content.size()
);
std::vector<char> buf;
std::ofstream responseFile("response.html");
DWORD bytesAvail = 0;
while(true)
{
res = ::InternetQueryDataAvailable(
hReq
, &bytesAvail
, 0
, 0
);
if (!res || 0 == bytesAvail)
{
break;
}
buf.resize(bytesAvail);
res = ::InternetReadFile(
hReq
, &buf[0]
, buf.size()
, &bytesAvail
);
buf.resize(bytesAvail);
std::copy(buf.begin(), buf.end(), std::ostream_iterator<char>(responseFile));
}
responseFile.close();
::InternetCloseHandle(hReq);
::InternetCloseHandle(hConn);
::InternetCloseHandle(hInet);
return 0;
}
The leak is the «static _Mtx_t at_thread_exit_mutex» declared in «crt\src\thr\xnotify.c», which is allocated once for the first created std::thread but never freed. So it's not a leak per say, more of a «skipped cleaning up after me»-issue.© Andreas Magnusson