I am trying to figure out how to serialize my XmlDocument correctly and send it through an HTTPWebRequest object.
Here is what I still have:
Stream requestStream; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/Track"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; requestStream = request.GetRequestStream(); XmlSerializerNamespaces xsm = new XmlSerializerNamespaces(); xsm.Add("", ""); // remove namespace XmlSerializer ser = new XmlSerializer(xmlRequest.GetType()); ser.Serialize(requestStream, xmlRequest); requestStream.Write(postData, 0, postData.Length); requestStream.Close();
A few things I donβt know about. I have 2 XmlDocuments that I need to send in the same HTTPWebRequest. I tried converting XmlDocuments to strings and just concatenating them (sending a string), but when I used StringBuilder / Writer, it adds:
<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://myNameSpace/">
I already have an ad in my XmlDocument objects, so now it's there twice, and I can't have the <string... part there. Is it easier to convert XmlDocuments to strings, then concatenate them and submit, or is there an easy way to send XmlDocuments as they are?
Edit:
See C # XmlDocument Nodes When I try to convert one of my XmlDocuments to a string, it displays as
<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://myNamespace/"> <TrackRequest> <Request> <TransactionReference> <CustomerContext>whatever</CustomerContext> </TransactionReference> </Request> <TrackingNumber>123</TrackingNumber> </TrackRequest> </string>
I want my root to be <TrackRequest>
source share