title: How to properly POST JSON array to avoid HTTP 400 Bad Request?
body: <p>I have a small C# app, which uses HttpClient to POST a JSON array to a REST API implemented in Java Jersey 2.0.</p>
  
  <p>My client code looks like this:</p>
  
  <pre><code>public class Customer {
    public string Name { get; set; }
    public string Address { get; set; }
  }
  
  Client.Customer customer1 = new Client.Customer {
    Name = "name 1", Address = "address 1"
  };
  Client.Customer customer2 = new Client.Customer {
    Name = "name 2", Address = "address 2"
  };
  
  List &lt; Client.Customer &gt; customerList = new List &lt; Client.Customer &gt; ();
  customerList.Add(customer1);
  customerList.Add(customer2);
  
  string json = JsonConvert.SerializeObject(customerList);
  
  EnvokeCreateCustomer("http://10.3.3.5:8080/", "jersey_test/webapi/customer", json).Wait();
  
  static async Task EnvokeReadCustomer(string baseUrl, string apiUrl) {
    RestClient.Client restClient = new RestClient.Client();
    await restClient.ReadCustomer(baseUrl, apiUrl);
  }
  
  public async Task CreateCustomer(string baseUrl, string apiUrl, string customer) {
    using(var client = new HttpClient()) {
      client.BaseAddress = new Uri(baseUrl);
      client.DefaultRequestHeaders.Accept.Clear();
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
      client.DefaultRequestHeaders.Add("Accept", "application/json");
  
      var response = await client.PostAsJsonAsync(apiUrl, customer);
      var p = response;
    }
  }
  </code></pre>
  
  <p>When I run this, I get HTTP 400 Bad Request.</p>
  
  <p>When I use a small Python HttpClient code against the same API, it runs fine:</p>
  
  <pre><code>import json
  import urllib2
  
  data = [{"name":"Customer 1", "address":"customer address 1"},
          {"name":"Customer 2", "address":"customer address 2"}]
  payload = json.dumps(data)
  
  req = urllib2.Request('http://10.3.3.5:8080/jersey_test/webapi/customer')
  req.add_header('Content-Type', 'application/json')
  
  response = urllib2.urlopen(req, json.dumps(data))
  </code></pre>
  
  <p>What should I change in my C# code to make this POST work?</p>