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 lacked a suitable constructor on legacy platforms (.NET 4.0 and earlier).

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 does not use a proxy by default

Rebex HttpRequest does not utilize system's default proxy. If you intend to connect via a proxy, use HttpRequestCreator'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.

HttpRequest lacks cookies API

At the moment, HttpRequest and HttpResponse lack CookieContainer property. We will add this soon. Until then, cookies must be accessed via custom code through Headers property.