title: How to find the reason for a bad request in CouchDB
body: <p>I'm bulk-uploading documents to a CouchDB with a System.Net.WebClient like this:</p>
  
  <pre><code>webClient.UploadString("couchdb.host.com:5984/db/_bulk_docs", "POST", json_data);
  </code></pre>
  
  <p>This usually works fine, but sometimes I get a WebException with a 'Bad Request' Status (400).
  Unfortunately, that's the only information I get, so I don't really know what causes the exception.</p>
  
  <p>I checked the logfiles under /var/log/couchdb/couchdb.log, but I did not get any further info there:</p>
  
  <pre><code>[notice] 2019-09-10T15:26:09.173949Z couchdb@host.com &lt;0.5318.568&gt; f50ab02d22 host.com:5984 x.x.x.x undefined POST /db/_bulk_docs 400 ok 75
  </code></pre>
  
  <p>So my questions are:</p>
  
  <ul>
  <li><p>Is there more information hidden somewhere in the WebException object and if so, where do I find it?</p></li>
  <li><p>is there a way to get more informations on the server side?</p></li>
  </ul>
  
  <p>My suspicion is that the documents I am trying to upload, are too big. How can I check that?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I dumped the faulting request into a file with:</p>
  
  <pre><code>        catch (WebException ex)
          {
              File.WriteAllText("C:\\temp\\couchdb_bad_request.json", json_data);
          }
  </code></pre>
  
  <p>and tried it again with:</p>
  
  <pre><code>curl -X POST http:/couchdb.host.com:5984/db/_bulk_docs -H "Content-Type: application/json" -d @couchdb_bad_request.json
  </code></pre>
  
  <p>This time I got a 201. So what's the difference between a curl and a WebClient request?</p>
  
  <p>My json data look like this:</p>
  
  <pre><code>{
    "docs": [
      {
        "Type": "Image",
        "_attachments": {
          "123_original.jpg": {
            "content_type": "image/jpeg",
            "data": "&lt;base64-encoded image data&gt;"
          }
        },
        "ID": "123",
        "_id": "123",
        "FileName": "some_file.jpg",
        "AttachmentMetaData": {
          "original": {
            "Width": 864,
            "Height": 576,
            "MD5Checksum": "a20ecae8e3a7df8cc8558a71efc2b573"
          }
        }
      },
      {...}
    ]
  }
  </code></pre>