title: Using WebClient to pass arrays as part of message body for post action
body: <p>I am writing a console application that needs to perform a POST to an MVC controller. I am using the WebClient class to perform the POST. But I'm having trouble understanding how to add arrays to the message body.</p>
  
  <p>For simple parameters, it seems to work if I do this:</p>
  
  <pre><code>         using (var client = new WebClient())
          {
  
              var values = new NameValueCollection 
              { 
                  { "userName", "userName" },
                  { "password", "passwordGoesHere"}
  
              };
              byte[] responseArray = client.UploadValues(String.Format("{0}/Mobile/StartSession", serverAddress), values);
              Debug.WriteLine(String.Format("\r\nResponse received was :\n{0}\n", Encoding.ASCII.GetString(responseArray)));
  
          }
  </code></pre>
  
  <p>I was trying to find how to pass arrays in the message body when using WebClient (for calling one of the other methods). I came across this solution: <a href="https://stackoverflow.com/questions/3942427/posting-arrays-in-webclient-c-net">POST&#39;ing arrays in WebClient (C#/.net)</a></p>
  
  <p>It appears the solution actually passes parameters in the query string (and not in the message body). This seems to work in any case, as the HttpPost method on the MVC controller is still receiving the correct information. However, another method requires that I pass an image as an array of bytes. This is too large to be passed in the querystring and so the call fails.</p>
  
  <p>So my question is, using the code I provided above, how can I add arrays in there as well. So an array of bytes for example, but also an array of strings.</p>
  
  <p>If any one can provide me with a solution it would be much appreciated, or if I'm incorrect in my thinking please let me know.</p>
  
  <p>Thanks</p>