I am trying to send a simple XML document to a third party automatically, the content is an URL encoded XML document, a view is being created using the following code:
Using client As New WebClient
Dim reqParm As New NameValueCollection
reqParm.Add("cxml-urlencoded", sXmlOrderMessage)
Dim respBytes = client.UploadValues(cXMLSettings.SupplierSetupUrl, "POST", reqParm)
Dim respBody = (New UTF8Encoding(False).GetString(respBytes))
End Using
This works and presents the necessary content. XML is built using the XmlTextWriter component, the title of the document is as follows:
Dim mem As New MemoryStream
Dim writer As New XmlTextWriter(mem, Encoding.UTF8)
writer.WriteStartDocument()
writer.WriteDocType("cXML", Nothing, "http://xml.cXML.org/schemas/cXML/1.1.009/cXML.dtd", Nothing)
writer.WriteStartElement("cXML")
writer.WriteAttributeString("payloadID", objCXMLDetails.PayloadID + Request.Url.Host)
writer.WriteAttributeString("xml:lang", "en-gb")
writer.WriteAttributeString("timestamp", DateTime.Now.ToString("o"))
After creating the XML, I then use the following to convert it to a string:
writer.WriteEndDocument()
writer.Flush()
Dim reader As New StreamReader(mem)
mem.Seek(0, SeekOrigin.Begin)
Return reader.ReadToEnd
This returns a string that I can then encode the URL.
XML return (I only show the title):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.1.009/cXML.dtd">
<cXML payloadID="20180305112030.15272.382530855@localhost" xml:lang="en-gb" timestamp="2018-03-05T11:20:30.9962738+00:00">
The problem is that when sending, I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.017/cXML.dtd"> -
<cXML timestamp="2018-03-05T08:46:58" payloadID="87f75924-9851-47c5-bd6d-76c723657476">
-
<Response>
<Status text="Not Acceptable org.jdom.input.JDOMParseException: Error on line 1: Content is not allowed in prolog." code="406" />
</Response>
</cXML>
I tried
- Removing UTF-8 encoding from XmlTextWriter.
- Removing a schema reference defined in DocType.
- - '<' .
.