title: Write JSON to Solr via HTTP/Post
body: <p>I am writing to Solr using JSON via HTTP/POST from a C#/Winforms/.NET4.0 app to speed up indexing and using the code below. I write a document to solr (based on these <a href="http://wiki.apache.org/solr/UpdateJSON/" rel="nofollow">instructions</a>) but keep getting a '400 bad request'. The JSON appears to be clean and no issues.</p>
  
  <p>It seems to be a syntax issue but I have been wrestling with this for last many hours to no avail. Any ideas on what is awry? All help appreciated.</p>
  
  <p>Here is the URI string being posted</p>
  
  <pre><code>"http://localhost:8080/solr/update/json -H 'Content-type:application/json' -d ' [ {\"UUID\":\"d2a174e4-81d6-487f-b68d-392be5d3d47a\",\"Extension\":\".AVI\",\"VideoFileName\":\"Clip 1.avi\"} ' ]"
  
  string uri = http://localhost:8080/solr/update/json;
  
  public bool WriteJSONToSolr(string uri, string json)
          {
              WebRequest request = WebRequest.Create(uri + " -H 'Content-type:application/json' -d ' [ " + json + " ' ]" );
              request.ContentType = "application/x-www-form-urlencoded";
              request.Method = "POST";
              byte[] bytes = Encoding.ASCII.GetBytes(json);
              Stream stream = null;
              try
              { // send the Post
                  request.ContentLength = bytes.Length;   //Count bytes to send
                  stream = request.GetRequestStream();
                  stream.Write(bytes, 0, bytes.Length);         //Send it
              }
              catch
              {
                  return false;
              }
              finally
              {
                  if (stream != null)
                  {
                      stream.Close();
                  }
              }
              System.Net.WebResponse response = request.GetResponse();
              if (response == null) return false;
  
              return true;
          }
  </code></pre>