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 also use that:
I found that the WebClient kept removing my User-Agent header after one request and I was tired of setting it each time. I used a hack to set the User-Agent permanently by making my own custom WebClient and overriding the GetWebRequest method. Hope this helps.
you can go here(msdn) for show a sample "proper" for add a user-agent in your WebClient for C# and Here(msdn) for show sample for Windows phone.
this is this sample for c# :
this is a sample for Windows Phone (silverlight):
or
As a supplement to the other answers, here is Microsoft's guidance for user agent strings for its browsers. The user agent strings differ by browser (Internet Explorer and Edge) and operating system (Windows 7, 8, 10 and Windows Phone).
For example, here is the user agent string for Internet Explorer 11 on Windows 10:
and for Internet Explorer for Windows Phone 8.1 Update:
Templates are given for the user agent strings for the Edge browser for Desktop, Mobile and WebView. See this answer for some Edge user agent string examples.
Finally, another page on MSDN provides guidance for IE11 on older desktop operating systems.
IE11 on Windows 8.1:
and IE11 on Windows 7: