title: How to set User Agent with System.Net.WebRequest in c#
body: <p>I'm trying to set User Agent with WebRequest, but unfortunately, I've only found how to do it using HttpWebRequest, so here is my code and I hope you can help me to set the User-Agent using WebRequest.</p>
  <p>here is my code</p>
  <pre><code>    public string Post(string url, string Post, string Header, string Value)
      {
          string str_ReturnValue = &quot;&quot;;
  
          WebRequest request = WebRequest.Create(url);
  
          request.Method = &quot;POST&quot;;
          request.ContentType = &quot;application/json;charset=UTF-8&quot;;                        
          request.Timeout = 1000000;
  
          if (Header != null &amp; Value != null)
          {
              request.Headers.Add(Header, Value);                                
          }
  
          using (Stream s = request.GetRequestStream())
          {
              using (StreamWriter sw = new StreamWriter(s))
                  sw.Write(Post);
          }
  
          using (Stream s = request.GetResponse().GetResponseStream())
          {                
              using (StreamReader sr = new StreamReader(s))
              {
                  var jsonData = sr.ReadToEnd();
                  str_ReturnValue += jsonData.ToString();
              }
          }
  
          return str_ReturnValue;
      }
  </code></pre>
  <p>I have tried with adding <code>request.Headers.Add(&quot;user-agent&quot;, _USER_AGENT);</code> but I receive an error message.</p>