title: Create a HttpWebRequest for a http://user:password@doamin/query Url
body: <p>I need to send a HttpWebRequest to a url with basic inline credentials as follows:  </p>
  
  <pre><code>http://user:password@doamin/query
  </code></pre>
  
  <p>I've tried setting the Url as is, but it didnt seem to pass the credentials (got 403).<br>
  Tried setting the Credentials property of HttpWebRequest:</p>
  
  <pre><code>request.Credentials = new NetworkCredentials("username","pasword")
  </code></pre>
  
  <p>And removing them from the url (resulting in <code>http://domain/query</code>) but still got the same result (403).  </p>
  
  <p>Using the Url directly from any browser succeeded so the credentials are Ok.  </p>
  
  <p>What am I missing?</p>
  
  <p><strong>[UPDATE - ANSWER]</strong><br>
  Here's the code that worked for me:  </p>
  
  <pre><code>string credentials = "username:password";
  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(formattedUrl);
  request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
  request.PreAuthenticate = true;
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>