最佳答案
为 WindowsPhone7的 WebClient 请求设置 User-Agent 头的正确方法是什么? 我找到了两个选项,但不确定哪一个是正确的。考虑一个 WebClient 对象:
WebClient client = new WebClient();
我看到了两个选择:
使用以下方法设置用户代理:
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?