Discussion:
Making a SSL Request using WinInet (upload file)
(too old to reply)
rranly
2004-09-14 14:13:02 UTC
Permalink
Having problems uploading a file to a secure site using WinInet. I found
this article,(http://support.microsoft.com/?kbid=168151) that is pretty
straight forward however, I am getting a Error on HttpSendRequestEx #997.

If I take the certificate off the IIS machine, I am able to change the
port in the InternetConnect call, and everything works well, as well as
remove "INTERNET_FLAG_SECURE" flag in the HttpOpenRequest call, and I am
able to successfully upload the file.

INTERNET_BUFFERS BufferIn = {0};
DWORD dwBytesRead;
DWORD dwBytesWritten;
BYTE pBuffer[1024]; // Read from file in 1K chunks
bool bRead, bReturn = FALSE; //assume error
HINSTANCE wininetDLL;
long retCode = 0;
bool bErrorReturn = TRUE;

BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );

wininetDLL = LoadLibrary("wininet.dll");
if(wininetDLL == NULL)
{
bReturn = FALSE;
return bReturn;
}
else
{
//Open Internet
HINTERNET hInternet = InternetOpen("Microsoft Internet Explorer",
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if(hInternet == NULL)
return FALSE;

//Open Connection
HINTERNET hConnect = InternetConnect(hInternet, Url, 443, "","",
INTERNET_SERVICE_HTTP, 0, 0);
if (hConnect == NULL)
return FALSE;

//Open Http Request
HINTERNET hRequest = HttpOpenRequest(hConnect, "PUT", FileName,
HTTP_VERSION, "", NULL, INTERNET_FLAG_SECURE, 0);
if (hRequest == NULL)
return FALSE;

//Create File
HANDLE hFile = CreateFile (FilePath, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;

BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
oLogFile << "File size is " << BufferIn.dwBufferTotal << "\n";

if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE, 0))
return FALSE;

DWORD sum = 0;
do
{
if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),
&dwBytesRead, NULL)))
{
return FALSE;
break;
}
if (!(bReturn=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
&dwBytesWritten)))
{
return FALSE;
break;
}
sum += dwBytesWritten;
}
while (dwBytesRead == sizeof(pBuffer));

CloseHandle (hFile);
oLogFile << "Actual written bytes: " << sum << "\n";

if(!HttpEndRequest(hRequest, NULL, 0, 0))
return FALSE;

bReturn = InternetCloseHandle(hInternet);
bReturn = InternetCloseHandle(hConnect);
bReturn = InternetCloseHandle(hRequest);

bErrorReturn = RecordError(CrystalInterfaceHeaderId, FileName,
"Success: File sent.");

oLogFile.clear();
oLogFile.close();
bReturn = TRUE;
}
}
return bReturn;
rranly
2004-09-14 14:29:08 UTC
Permalink
I'm sorry. I've obviously attached my code, and looking for some direction
as too what I may be missing.

I appreciate all your help!

Loading...