title: how to send a http basic auth post?
body: <p>I have been given the task to create a http post using basic auth. 
  I am developing in C# in an asp.net MVC application. </p>
  
  <p>I have also been given this example. </p>
  
  <pre><code>{
  POST /v2/token_endpoint HTTP/1.1
  Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=
  Accept: application/json
  Content-Type: application/x-www-form-urlencoded
  User-Agent: Java/1.6.0_33
  Host: api.freeagent.com
  Connection: close
  Content-Length: 127
  
  grant_type=authorization_code&amp;code=12P3AsFZXwXjd7SLOE1dsaX8oCgix&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth
  }
  </code></pre>
  
  <p>My question is how do i code this in C#?
  If more information is need just ask, thanks in advance</p>
  
  <p>edit: I have made some progress but I have not added the grant_type</p>
  
  <pre><code>public void AccessToken(string code)
      {
          string url = @"https://api.freeagent.com/v2/token_endpoint";
          WebClient client = new WebClient();
          string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(ApiKey + ":" + ApiSecret));
          client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
          client.Headers[HttpRequestHeader.Accept] = "application/json";
          client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
          client.Headers[HttpRequestHeader.UserAgent] = "Java/1.6.0_33";
          client.Headers[HttpRequestHeader.Host] = "api.freeagent.com";
          client.Headers[HttpRequestHeader.Connection] = "close";
          client.Headers["grant_type"] = "authorization_code";
  
          var result = client.DownloadString(url);
      }
  </code></pre>
  
  <p>So how do i add: grant_type=authorization_code&amp;code=12P3AsFZXwXjd7SLOE1dsaX8oCgix&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth to the post?</p>