This method will block the current thread until a connection has
been established or the timeout period has elapsed. To prevent it from
blocking the main user interface thread, the application should create
a background worker thread and establish a connection by calling the
Connect method in that thread. If the application
requires multiple simultaneous connections, it is recommended you
create a worker thread for each connection.
The dwOptions argument can be used to specify the threading
model that is used by the class when a connection is established. By
default, the client session is initially attached to the thread that
created it. From that point on, until the connection is terminated,
only the owner may invoke methods in that instance of the class. The
ownership of the class instance may be transferred from one thread to
another using the AttachThread method.
Specifying the HTTP_OPTION_FREETHREAD option enables any thread to
call methods in any instance of the class, regardless of which thread
created it. It is important to note that this option disables certain
internal safety checks which are performed by the class and may
result in unexpected behavior unless access to the class instance is
synchronized. If one thread calls a method in the class, it must
ensure that no other thread will call another method at the same time
using the same instance.
If the HTTP_OPTION_KEEPALIVE option is specified and the server
does not support persistent connections, the client will automatically
reconnect when each resource is requested. Although it will not
provide any performance benefits, this allows the option to be used
with all servers. This option is automatically enabled when using
HTTP/2.
Under some circumstances, a server may forcibly close or abort
a connection if the request fails. For example, this can happen when a
malformed request is submitted to the server or a server-side error
occurs. When this happens, the application will need to disconnect
from the server and establish a new connection, even if the keep-alive
option has been specified.
Applications should use HTTP_VERSION_DEFAULT as the value for
the dwVersion parameter. This will default to an appropriate
version for the Windows platform and ensures the broadest compatibility
with most servers. If your application specifies HTTP_VERSION_20,
a secure connection using TLS 1.2 or later will always be used. The
minimum required platform for HTTP/2 support is Windows 10 (Build 1903)
or Windows Server 2019. Earlier versions of the Schannel SSP do not
support the features required for a secure HTTP/2 connection.
If your application requests a HTTP/2 connection and the server
only accepts earlier versions of the protocol, the client will attempt
to automatically downgrade the request to HTTP/1.1. If a connection
using an earlier version of the protocol cannot be established, the
method will fail and return a value of zero.