Question

I have succeffuly connected to the service using the code below but I need to save the response to the XML file results.xml.

Dim xml As New System.Xml.XmlDocument()

     xml.Load("c:\testfile.xml")


    Dim req = WebRequest.Create("????")
    req.Method = "POST"
    req.ContentType = "application/xml"

    Using ms = New MemoryStream()
        xml.Save(ms)
        req.ContentLength = ms.Length
        ms.WriteTo(req.GetRequestStream())
    End Using

    Dim results As XmlReader = XmlTextReader.Create(req.GetResponse().GetResponseStream)

    Dim settings As New XmlWriterSettings()
    settings.Indent = True
    settings.IndentChars = vbTab
    Dim writer As XmlWriter = XmlWriter.Create("c:\results.xml", settings)
    writer.WriteNode(results, False)

The code runs but only produces a blank file. Any help would be gratefully appreciated.

Was it helpful?

Solution

Add one more setting:

settings.CloseOutput = True

Also did you miss at the end?

writer.WriteEndDocument()
writer.Flush()
writer.Close()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top