INFO: Migrating from .NET HttpWebRequest to Rebex HttpRequest
In many cases, upgrading from .NET's System.Net.HttpWebRequest
to Rebex HttpRequest
is
straightforward. However, please be aware that for various reasons,
it is not a one-to-one replacement. This article discusses common pitfalls.
HttpRequest does not inherit from HttpWebRequest
Both .NET's System.Net.HttpWebRequest
and Rebex HttpRequest
inherit from System.Net.WebRequest
.
In an ideal world, we would inherit HttpRequest
from HttpWebRequest
to ensure a smooth migration.
Unfortunately, this is not possible because HttpWebRequest
was not designed to allow inheritance and lacks a suitable constructor.
This could pose a problem when using Rebex HTTPS within an application or with a library that has been designed to only use HttpWebRequest
and assume that WebRequest.Create
will always return an instance of this object.
The recommended workaround is to modify existing application or library code
to expect HttpRequest
instead of HttpWebRequest
.
HttpRequest does not use ServicePointManager
Rebex HttpRequest
does not utilize ServicePointManager.ServerCertificateValidationCallback
.
To implement a custom server certificate validation routine, use HttpRequestCreator
's
custom certificate validation event.
HttpRequest uses a different proxy API
Rebex HttpRequest
does not support the Proxy
property and does not utilize system's default proxy.
If you intend to connect via a proxy, use HttpRequestCreator
's or WebClient
's
proxy API.
HttpRequest does not establish connection automatically by default
On .NET Compact Framework, .NET's HttpWebRequest
class attempts to establish an Internet connection when a network is not accessible.
Rebex HttpRequest
does not do this by default. To enable equivalent behavior, set HttpRequestCreator
's
Settings.AutoConnectToInternet
to Rebex.Net.ConnectionManagement.AutoConnectType.Enabled
.