Discussion:
WinHTTP PUT
(too old to reply)
MartinF
2008-05-09 20:55:28 UTC
Permalink
Hello,

I am attempting to upload a small test file that only contains 'Abc' to my
IIS server. I use the below listed sample test harness that executes without
a hiccup, yet I am not able to see the uploaded file. I use IIS 7 running on
Windows Server 2008 in a VirtualPC session. Security and sharing is wide
open as well as browsing.

I thank you in advance for your help,
Martin

int _tmain(int argc, _TCHAR* argv[])
{
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;

// Sample data to PUT in the file
LPTSTR pszData = L"Abc";
DWORD dwLen = wcslen( pszData ) * sizeof(TCHAR);

// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"WinHTTPTest",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS,
0);

// Specify an HTTP server.
if (hSession)
{
hConnect = WinHttpConnect( hSession, L"192.168.1.100",
INTERNET_DEFAULT_PORT, 0);
}

// Create an HTTP Request handle.
if ( hConnect )
{
hRequest = WinHttpOpenRequest(
hConnect,
L"PUT",
L"/Upload/newfile.txt",
NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0
);
}

// Send a Request.
if (hRequest)
{
bResults = WinHttpSendRequest(
hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
pszData, dwLen, dwLen, 0
);
}

if ( bResults == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}

// Close open handles.
if (hRequest)
{
if ( WinHttpCloseHandle(hRequest) == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
}

if (hConnect)
{
if ( WinHttpCloseHandle(hConnect) == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
}

if (hSession)
{
if ( WinHttpCloseHandle(hSession) == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
}

return( 0 );
}
Volodymyr M. Shcherbyna
2008-05-13 08:37:00 UTC
Permalink
What error do you get?
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by MartinF
Hello,
I am attempting to upload a small test file that only contains 'Abc' to my
IIS server. I use the below listed sample test harness that executes
without a hiccup, yet I am not able to see the uploaded file. I use IIS 7
running on Windows Server 2008 in a VirtualPC session. Security and
sharing is wide open as well as browsing.
I thank you in advance for your help,
Martin
int _tmain(int argc, _TCHAR* argv[])
{
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
// Sample data to PUT in the file
LPTSTR pszData = L"Abc";
DWORD dwLen = wcslen( pszData ) * sizeof(TCHAR);
// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"WinHTTPTest",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);
// Specify an HTTP server.
if (hSession)
{
hConnect = WinHttpConnect( hSession, L"192.168.1.100",
INTERNET_DEFAULT_PORT, 0);
}
// Create an HTTP Request handle.
if ( hConnect )
{
hRequest = WinHttpOpenRequest(
hConnect,
L"PUT",
L"/Upload/newfile.txt",
NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0
);
}
// Send a Request.
if (hRequest)
{
bResults = WinHttpSendRequest(
hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
pszData, dwLen, dwLen, 0
);
}
if ( bResults == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
// Close open handles.
if (hRequest)
{
if ( WinHttpCloseHandle(hRequest) == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
}
if (hConnect)
{
if ( WinHttpCloseHandle(hConnect) == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
}
if (hSession)
{
if ( WinHttpCloseHandle(hSession) == FALSE )
{
printf("Error %d has occurred.\n",GetLastError());
}
}
return( 0 );
}
Continue reading on narkive:
Loading...