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.Ne t.WebRequest.Cr eate(fullUrl),
System.Net.Http WebRequest)
webRequest.Meth od = "POST"
webRequest.Cont entType = "text/xml"
Dim streamPingReque st As Stream
streamPingReque st = webRequest.GetR equestStream
Dim xmlPing2 As New XmlTextWriter(s treamPingReques t,
Encoding.UTF8)
' Opens the document
xmlPing2.WriteS tartDocument()
xmlPing2.Format ting = Formatting.Inde nted
xmlPing2.WriteS tartElement("Ac cessRequest")
xmlPing2.WriteE lementString("A ccessLicenseNum ber", "123456")
xmlPing2.WriteE lementString("U serId", "userid")
xmlPing2.WriteE lementString("P assword", "password")
xmlPing2.WriteE ndElement()
xmlPing2.WriteE ndDocument()
xmlPing2.WriteS tartDocument()
xmlPing2.WriteS tartElement("Sh ipmentConfirmRe quest") '
xml:lang=""en-US"" > " & _
xmlPing2.WriteA ttributeString( "xml:lang", "en-US")
xmlPing2.WriteS tartElement("Re quest")
xmlPing2.WriteS tartElement("Tr ansactionRefere nce")
xmlPing2.WriteE lementString("C ustomerContext" , "ShipConfirmUS" )
xmlPing2.WriteE lementString("X pciVersion", "1.0001")
xmlPing2.WriteE ndElement() '"</TransactionRefe rence>" & _
xmlPing2.WriteE lementString("R equestAction", "ShipConfir m")
xmlPing2.WriteE lementString("R equestOption", "nonvalidat e")
xmlPing2.WriteE ndElement() '"</Request>" & _
xmlPing2.WriteE ndElement() '"</ShipmentConfirm Request>"
xmlPing2.WriteE ndDocument()
' close writer
xmlPing2.Close( )
webRequest.Allo wAutoRedirect = bAllowAutoRedir ect
'webRequest.Max imumAutomaticRe directions = 50
webRequest.Time out = iTimeout
'Send the request and wait for a response.
Try
webResponse = CType(webReques t.GetResponse() ,
System.Net.Http WebResponse)
Select Case (webResponse.St atusCode)
Case System.Net.Http StatusCode.OK
'read the content from the response
Dim responseStream As System.IO.Strea m = _
webResponse.Get ResponseStream( )
Dim responseEncodin g As System.Text.Enc oding = _
System.Text.Enc oding.UTF8
' Pipes the response stream to a higher level stream
reader with the required encoding format.
Dim responseReader As New
StreamReader(re sponseStream, responseEncodin g)
responseContent = responseReader. ReadToEnd()
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.Ne t.WebRequest.Cr eate(fullUrl),
System.Net.Http WebRequest)
webRequest.Meth od = "POST"
webRequest.Cont entType = "text/xml"
Dim streamPingReque st As Stream
streamPingReque st = webRequest.GetR equestStream
Dim xmlPing2 As New XmlTextWriter(s treamPingReques t,
Encoding.UTF8)
' Opens the document
xmlPing2.WriteS tartDocument()
xmlPing2.Format ting = Formatting.Inde nted
xmlPing2.WriteS tartElement("Ac cessRequest")
xmlPing2.WriteE lementString("A ccessLicenseNum ber", "123456")
xmlPing2.WriteE lementString("U serId", "userid")
xmlPing2.WriteE lementString("P assword", "password")
xmlPing2.WriteE ndElement()
xmlPing2.WriteE ndDocument()
xmlPing2.WriteS tartDocument()
xmlPing2.WriteS tartElement("Sh ipmentConfirmRe quest") '
xml:lang=""en-US"" > " & _
xmlPing2.WriteA ttributeString( "xml:lang", "en-US")
xmlPing2.WriteS tartElement("Re quest")
xmlPing2.WriteS tartElement("Tr ansactionRefere nce")
xmlPing2.WriteE lementString("C ustomerContext" , "ShipConfirmUS" )
xmlPing2.WriteE lementString("X pciVersion", "1.0001")
xmlPing2.WriteE ndElement() '"</TransactionRefe rence>" & _
xmlPing2.WriteE lementString("R equestAction", "ShipConfir m")
xmlPing2.WriteE lementString("R equestOption", "nonvalidat e")
xmlPing2.WriteE ndElement() '"</Request>" & _
xmlPing2.WriteE ndElement() '"</ShipmentConfirm Request>"
xmlPing2.WriteE ndDocument()
' close writer
xmlPing2.Close( )
webRequest.Allo wAutoRedirect = bAllowAutoRedir ect
'webRequest.Max imumAutomaticRe directions = 50
webRequest.Time out = iTimeout
'Send the request and wait for a response.
Try
webResponse = CType(webReques t.GetResponse() ,
System.Net.Http WebResponse)
Select Case (webResponse.St atusCode)
Case System.Net.Http StatusCode.OK
'read the content from the response
Dim responseStream As System.IO.Strea m = _
webResponse.Get ResponseStream( )
Dim responseEncodin g As System.Text.Enc oding = _
System.Text.Enc oding.UTF8
' Pipes the response stream to a higher level stream
reader with the required encoding format.
Dim responseReader As New
StreamReader(re sponseStream, responseEncodin g)
responseContent = responseReader. ReadToEnd()