Hello, Im trying to post an XML to a UPS server and the XML has a double
header, one for the autorization section and one for the body. The following
is my code. When I run it I have the error The XML document is not well
formed. If I create this XML on a file and try to open with the XML editor I
have an error, that says I can't have to headers on the document ans it's
right because I need to have 2 headers. How can avoid this? or how can I
post 2 xmls? I need to send both sections to the UPS server. Here is my
code:
fullUrl = "https://wwwcie.ups.com/ups.app/xml/ShipConfirm"
webRequest = CType(System.Net.WebRequest.Create(fullUrl),
System.Net.HttpWebRequest)
webRequest.Method = "POST"
webRequest.ContentType = "text/xml"
Dim streamPingRequest As Stream
streamPingRequest = webRequest.GetRequestStream
Dim xmlPing2 As New XmlTextWriter(streamPingRequest,
Encoding.UTF8)
' Opens the document
xmlPing2.WriteStartDocument()
xmlPing2.Formatting = Formatting.Indented
xmlPing2.WriteStartElement("AccessRequest")
xmlPing2.WriteElementString("AccessLicenseNumber", "123456")
xmlPing2.WriteElementString("UserId", "userid")
xmlPing2.WriteElementString("Password", "password")
xmlPing2.WriteEndElement()
xmlPing2.WriteEndDocument()
xmlPing2.WriteStartDocument()
xmlPing2.WriteStartElement("ShipmentConfirmRequest ") '
xml:lang=""en-US"" > " & _
xmlPing2.WriteAttributeString("xml:lang", "en-US")
xmlPing2.WriteStartElement("Request")
xmlPing2.WriteStartElement("TransactionReference")
xmlPing2.WriteElementString("CustomerContext", "ShipConfirmUS")
xmlPing2.WriteElementString("XpciVersion", "1.0001")
xmlPing2.WriteEndElement() '"</TransactionReference>" & _
xmlPing2.WriteElementString("RequestAction", "ShipConfirm")
xmlPing2.WriteElementString("RequestOption", "nonvalidate")
xmlPing2.WriteEndElement() '"</Request>" & _
xmlPing2.WriteEndElement() '"</ShipmentConfirmRequest>"
xmlPing2.WriteEndDocument()
' close writer
xmlPing2.Close()
webRequest.AllowAutoRedirect = bAllowAutoRedirect
'webRequest.MaximumAutomaticRedirections = 50
webRequest.Timeout = iTimeout
'Send the request and wait for a response.
Try
webResponse = CType(webRequest.GetResponse(),
System.Net.HttpWebResponse)
Select Case (webResponse.StatusCode)
Case System.Net.HttpStatusCode.OK
'read the content from the response
Dim responseStream As System.IO.Stream = _
webResponse.GetResponseStream()
Dim responseEncoding As System.Text.Encoding = _
System.Text.Encoding.UTF8
' Pipes the response stream to a higher level stream
reader with the required encoding format.
Dim responseReader As New
StreamReader(responseStream, responseEncoding)
responseContent = responseReader.ReadToEnd()