I am using the WebClient class in .NET 2.0 to perform an HTTP POST over SSL.
Currently I'm manually setting the user-agent header like so:
wc = new WebClient();
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
This works fine, except for when I make the request through a proxy server that does HTTP tunnelling and expects a specific user-agent header in the HTTP CONNECT command.
When a proxy acts as a tunnel for SSL, it initially recieves an HTTP CONNECT which tells it where the client is trying to connect to.
The problem is that if you set the user-agent header in .NET either via HttpWebRequest.UserAgent, or WebClient.Headers.Add, it does not add it to the initial CONNECT request. It does add it to subsequent SSL traffic, but that's not what is needed.
If this was C++ I would simply call WinHttpOpen() to create the sesson and set the pwszUserAgent param to set the user agent for the whole session. Unfortunately I cannot find an equivalent in .NET.
Can anyone point me in the right direction? I'm sure that someone else must have come across this problem building client apps in .NET.