Hi all

Has anyone had any experience of writing multiple documents in a single request 
using the REST API?  I'm tried to do this using the C# code at the bottom of 
the email but when I ran the code, I got back the below response.  I'm not sure 
what is happening here.  The response suggests that MarkLogic is expecting the 
multipart body to be an XML document, which doesn't sound right.  Is anyone 
able to shed any light on why my code isn't working?

RESPONSE
<error-response xmlns="http://marklogic.com/xdmp/error";>
  <status-code>400</status-code>
  <status>Bad Request</status>
  <message-code>XDMP-DOCROOTTEXT</message-code>
  <message>XDMP-DOCROOTTEXT: xdmp:get-request-part-body("xml") -- Invalid root 
text "&amp;#10;--BOUNDARY&amp;#10;Content-Type: 
application/xml&amp;#10;Content-Disposition: attachment; 
filename=&amp;quot;/DocY.xml&amp;quot;&amp;#10;&amp;#10;" at  line 6</message>
</error-response>

CODE
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;

namespace MultipartTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // SET UP HTTPCLIENT
            CredentialCache credCache = new CredentialCache();
            HttpClient httpClient = new HttpClient(new HttpClientHandler { 
Credentials = credCache });
            credCache.Add(new Uri("http://localhost:port";), "Digest", new 
NetworkCredential("username", "pwd", "/"));
            httpClient.BaseAddress = new Uri("http://localhost:port";);
            httpClient.DefaultRequestHeaders.Accept.Add(new 
MediaTypeWithQualityHeaderValue("application/xml"));
            MultipartContent multipartContent = new MultipartContent("mixed", 
"BOUNDARY");

            // ADD FIRST DOCUMENT
            StringContent docx = new StringContent("<abc>abc</abc>");
            docx.Headers.ContentType = new 
MediaTypeHeaderValue("application/xml");
            docx.Headers.ContentDisposition = new 
ContentDispositionHeaderValue("attachment");
            docx.Headers.ContentDisposition.FileName = "/DocX.xml";
            multipartContent.Add(docx);

            // ADD SECOND DOCUMENT
            StringContent docy = new StringContent("<abc>ghi</abc>");
            docy.Headers.ContentType = new 
MediaTypeHeaderValue("application/xml");
            docy.Headers.ContentDisposition = new 
ContentDispositionHeaderValue("attachment");
            docy.Headers.ContentDisposition.FileName = "/DocY.xml";
            multipartContent.Add(docy);

            // MAKE REQUEST
            HttpResponseMessage response = 
httpClient.PostAsync("/v1/documents", multipartContent).Result;
            var marklogicResponseText = response.Content.ReadAsStringAsync();
            Console.WriteLine(marklogicResponseText.Result.ToString());

            Console.ReadLine();
        }
    }
}

Ashley Cousins
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to