cURL / Mailing Lists / curl-library / Single Mail


Problem posting XML (content is not allowed in prolog)

From: BINETTE Pascal <>
Date: Tue, 17 Feb 2009 15:01:42 -0500



I've been spending about 5 days on this problem, and I can't get this to work. Basically I'm trying to communicate with an XML Server, and while I can communicate with the server, it doesn't recognize what I'm sending it; I can getting the "content is not allowed in prolog" response.


The form I need to emulate is this:


<form action="eex-xmlserver/request" method="post"



                        Please choose an request file(*.xml) from your workstation, which

                        should be processed:



                        <input name="xml" type="file" size="50" maxlength="1000000"


                        <input type="submit">




Here's also a sample XML file I'm trying to send (this works when I use an online html form):


<?xml version="1.0" encoding="UTF-8"?>








I tried just about everything, encoding in several formats (URL encoding, Base 64, XML entities), I also tried using the regular POST versus the HTTP POST, I tried sending a file versus sending the XML tags as a string, etc. I'm now out of options.


If anyone has experience with this, I would greatly appreciate your help. Here's my current test code:



struct curl_httppost* post = NULL;

struct curl_httppost* last = NULL;


curl = curl_easy_init();

if (curl == NULL)

            AfxMessageBox("init failed");


// reading the XML file, and encoding its content

CStdioFile testfile;

testfile.Open("C:\\TEMP\\login_UTF8.xml", CFile::modeRead);

DWORD file_len = testfile.GetLength();

char *pbuf = new char[file_len];


testfile.Read(pbuf, file_len);


CString encodedXML = URLEncode(pbuf);

std::string response_string = "";


curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/eex-xmlserver/eex-xmlserver/");

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &apui_EASY_class::write_data);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);


curl_formadd(&post, &last, CURLFORM_COPYNAME, "xml",

             CURLFORM_COPYCONTENTS, encodedXML,

             CURLFORM_CONTENTTYPE, "text/xml",



curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);


// I tried a regular POST, but I don't think it is recognized as a request

// curl_easy_setopt(curl, CURLOPT_POSTFIELDS,pbuf);


// I also tried adding headers as follows

//struct curl_slist* http_header = NULL;

//http_header = curl_slist_append(http_header, "Content-Type: text/xml");

//curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header);



CURLcode res = curl_easy_perform(curl);






Thank you,

Best regards,



IMDS Software

Software Consultant

Technical Sales Engineer


Tel: + 1 514 842 6367 ext. 232

Fax: + 1 514 842 3380

Email: < <> >


IMDS scanner sales, mailroom solutions, cheque and cheque clearance processing, OCR, ICR, IWR

vente de numériseurs, solution pour les salles courrier, traitement du chèque et de l'encaissement, ROC, RIC, RIM

Received on 2009-02-17