What is the proper way of setting the User-Agent header for a WebClient request for Windows Phone 7?
I found 2 options, but not sure which one is the correct one. Considering a WebClient object:
WebClient client = new WebClient();
I saw 2 options:
-
set the User-Agent using:
client.Headers["User-Agent"] = "myUserAgentString"; -
set the User-Agent using the WebHeaderCollection:
WebHeaderCollection headers = new WebHeaderCollection(); headers[HttpRequestHeader.UserAgent] = "userAgentString"; client.Headers = headers;
Can you please advise which of the 2 methods above is the proper one?
You can check the
WebClientdocumentation for a C# sample that adds a User-Agent to yourWebClientand here for a sample for Windows Phone.This is the sample for C#:
This is a sample for Windows Phone (Silverlight):