Home > Uncategorized > Overriding the Date in a WebClient Request in C#

Overriding the Date in a WebClient Request in C#

The WebClient object in C# greatly simplifies the actions of making HTTP GET and POST requests, however, when you need to edit an “Under the hood” property, then you find that WebClient has hidden this functionality from you.

In this example, I want to override the Date property of the HTTP request, effectively sending a request to the server, but saying it was sent at a different time. This is not a property you often want to mess with, but you can do it as follows;

private class SpecializedWebClient : WebClient
    public DateTime Date { get; set; }
    protected override WebRequest GetWebRequest(Uri address)
	var request = base.GetWebRequest(address) as HttpWebRequest;
	if (request != null) request.Date = Date;
	return request;

I hope someone finds this useful!

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: