c++winapiwininetwinhttp

Do WinInet or WinHTTP support custom ports? If so, how do I implement it?


I am trying to download a file using both HTTP and HTTPS (in different scenarios) from a service which defaults to using ports 5080 and 5443, respectively. I wanted to use WinInet (or WinHTTP) as they're native to Windows, but it appears that both WinInet and WinHTTP only support using port 80 or port 443, and do not support specifying anything else.

Is it possible to specify a different port, and I've overlooked something? If not, is the next-best native option to drop down to using WinSock?

Edit: As answered below, the third parameter is of type INTERNET_PORT, but will accept any DWORD. Microsoft's documentation is confusing, as written here, InternetConnect, it says "nServerPort can be one of the following values.", which makes one believe only the provided constants are valid.

Instead, you can provide any port value (of type DWORD).

I submitted feedback on the InternetConnect documentation page, so hopefully this will be clearer for future readers.


Solution

  • WinInet's InternetConnect() and WinHTTP's WinHttpConnect() both let you specify any port number you want in their respective nServerPort parameters. You don't have to use the pre-defined constants like INTERNET_DEFAULT_HTTP(S)_PORT.