On IIS 6 I have created an http handler. I use a query string parameter in a URL to pass in an ID, do some database calls, then write out some XML (not using XML classes, just with context.Response.Write). I have it all working in a web page. By "working" I mean I can view the XML in a web browser. What I want to do is execute a simple cURL request that feeds this page's XML content to a proprietary API.
Currently, the only way I can get it to work is if I view source on my web page copy and paste my XML text into a text editor and save the text as UTF-8. When I run the cURL request on this saved text file, everything is fine. However, when I pass the URL that generates the XML to the cURL request, the API always complains with this reply:
The XML submitted is not well formed: Fatal Error 4: Start tag expected, '<' not found Line: 1 Column: 1
I validated my XML, no errors.
The examples in the documentation I have to work with show UTF-8 encoding in the XML document.
I tried to set the encoding in my handler (C#) like this:
context.Response.ContentEncoding = Encoding.UTF8;
The HTTP headers show;
Content-Type: text/html; charset=utf-8
I also tried setting the content type like this:
//context.Response.ContentType = "text/xml";
//context.Response.Charset = "utf-8";
I also tried a url encoding method on all of the XML that I am outputting from my handler. Even when I view it in the browser (view source), I get the < in the first line.
But I always get the same error from the API (above), that the first character is not <
The FIRST line in my generated XML document is always: <?xml version="1.0" encoding="UTF-8"?> or in the case of passing all the text through an encoder <xml version"1.0" .....etc.
I want to be able to pass my data via command line via the cURL request to my XML building http handler, but I can't get past this.