要将文件发送到服务器,我在Windows中执行HTTPS put请求,如下所示:
hSession = WinHttpOpen( L"Agent/1.0",..
hConnect = WinHttpConnect(hSession,..
hRequest = WinHttpOpenRequest( hConnect, L"PUT",..
WinHttpSetCredentials(hRequest,..
WinHttpAddRequestHeaders( hRequest,..
WinHttpSendRequest( hRequest,..
WinHttpWriteData(hRequest,..
WinHttpReceiveResponse(hRequest,..
WinHttpQueryHeaders(hRequest,..
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
为每个文件运行此命令包,应将其发送到服务器。从头开始为每个要发送的文件建立连接会产生额外的开销。现在我正在寻找一种减少这种开销的方法。
所以我有两个问题:
答案 0 :(得分:2)
答案如下:
这是代码草案:
hSession = WinHttpOpen( L"Agent/1.0",..
hConnect = WinHttpConnect(hSession,..
for (all_files_to_upload) {
hRequest = WinHttpOpenRequest( hConnect, L"PUT",..
WinHttpSetCredentials(hRequest,..
WinHttpAddRequestHeaders( hRequest,..
WinHttpSendRequest( hRequest,..
WinHttpWriteData(hRequest,..
WinHttpReceiveResponse(hRequest,..
WinHttpQueryHeaders(hRequest,..
WinHttpCloseHandle(hRequest);
}
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);