I am trying to use WinHTTP to connect to server, unfortunately when i am trying to upgrade the protocol from http to webscoket, the API WinHttpSetOption fails.
hSessionHandle = WinHttpOpen(L"WebSocket sample",WINHTTP_ACCESS_TYPE_NO_PROXY,NULL, NULL,0);
hConnectionHandle = WinHttpConnect(hSessionHandle, L"localhost",INTERNET_DEFAULT_HTTP_PORT, 0);
hRequestHandle = WinHttpOpenRequest(hConnectionHandle,L"GET",L"/ws",NULL,NULL,NULL, 0);
// Request protocol upgrade from http to websocket.
fStatus = WinHttpSetOption(hRequestHandle,WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET,NULL,0);
if (!fStatus)
{
dwError = GetLastError();
goto quit;
}
fStatus
returns FALSE, with GetLastError
returning error code 12009 which says
ERROR_WINHTTP_INVALID_OPTION
12009: A request to WinHttpQueryOption or WinHttpSetOption specified an invalid option value.
The above code is taken from the Microsoft WinHttp WebSocket demo (new GitHub home)
My system is Windows 7. Does the OS need to be Windows 8 or above? Any clues of this API fail?