title: How to set User-Agent in WebClient
body: <p>I used the code below to open a stream request to a youtube video, but it always return an exception "The remote server returned an error: NotFound". Then I tried to use Fiddler to detect the problem, and I saw that the WebClient auto set User-Agent field to NativeHost, not my User-Agent as below.</p>
  
  <p><strong>My code to send a request to youtube:</strong></p>
  
  <pre><code>private static Task&lt;string&gt; HttpGet(string uri)
  {
      var task = new TaskCompletionSource&lt;string&gt;();
  
      var web = new WebClient();
      web.OpenReadCompleted += (sender, args) =&gt;
      {
          if (args.Cancelled)
              task.SetCanceled();
          else if (args.Error != null)
              task.SetException(args.Error);
          else
          {
              //var bytes = args.Result.ReadToEnd();
              byte[] bytes = new byte[] { };
              using (MemoryStream memoryStream = new MemoryStream())
              {
                  args.Result.CopyTo(memoryStream);
                  bytes = memoryStream.ToArray();
  
                  task.SetResult(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
              }
          }
      };
  
      web.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
      web.OpenReadAsync(new Uri(uri));
  
      return task.Task;
  }
  </code></pre>
  
  <p><strong>Headers that were captured from Fiddler:</strong></p>
  
  <pre><code>CONNECT www.youtube.com:443 HTTP/1.0
  User-Agent: NativeHost
  Host: www.youtube.com:443
  Content-Length: 0
  Connection: Keep-Alive
  Pragma: no-cache
  </code></pre>
  
  <p>Please give me some advice. Many thanks</p>