VC++ 用WinInet发送HTTP请求和上传文件
最新推荐文章于 2024-03-29 15:16:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)
void CxxxApp::HttpRequest(std::pair nvps[], std::wstring files, std::string method = "POST"){char* buffer = NULL;ULONGLONG dwLength = ReadFileContent(_T("C:\\Users\\Data.log"), buffer);char fieldname[] = "upfile";char file[] = "readme.txt";char boundary[] = "---------------------------lummetricwebclient";char* headers = (char*)malloc(sizeof(char)*(1024));sprintf_s(headers, 1024, "%s%s", "Content-Type: multipart/form-data; boundary=", boundary);char* frmdata = (char*)malloc(sizeof(char)*(dwLength + 1024));ZeroMemory(frmdata, dwLength + 1024);char* formdataTemplate = "%s\r\n--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s";int x = sizeof(nvps);for (int i = 0; i < 2; i++) {sprintf_s(frmdata, (dwLength + 1024), formdataTemplate, frmdata, boundary, nvps[i].first.c_str(), nvps[i].second.c_