title: Set a body for WebClient when making a Post Request
body: <p>So I have an api that I want to call to.  The first call is an ahoy call and in the body of the request I need to send the ship_type, piratename and my piratepass.  I then want to read the response which has my treasure booty that i will use for later.</p>
  
  <p>I'm able to do this with web request.  but i feel like there is a better way to do it with webclient.  </p>
  
  <p>(way I currently do it in webrequest)</p>
  
  <pre><code>        //Credentials for the Pirate api
          string piratename = "IvanTheTerrible";
          string piratepass= "YARRRRRRRR";
  
          string URI = "https://www.PiratesSuperSecretHQ.com/sandyShores/api/respectmyauthority";
  
          WebRequest wr = WebRequest.Create(URI);
  
          wr.Method = "POST";
          wr.ContentType = "application/x-www-form-urlencoded";
  
          string bodyData = "ship_type=BattleCruiser&amp;piratename=" + piratename + "&amp;piratepass=" + piratepass;
  
          ASCIIEncoding encoder = new ASCIIEncoding();
  
          byte[] byte1 = encoder.GetBytes(bodyData);
  
          wr.ContentLength = byte1.Length;
          //writes the body to the request
          Stream newStream = wr.GetRequestStream();
  
          newStream.Write(byte1, 0, byte1.Length);
          newStream.Close();            
  
          WebResponse wrep = wr.GetResponse();
  
          string result;
  
          using (var reader = new StreamReader(wrep.GetResponseStream()))
          {
              result = reader.ReadToEnd(); // do something fun...
          }
  </code></pre>
  
  <p>Thanks in advance either way.</p>