0

我已使用以下代码成功连接到服务,但我需要将响应保存到 XML 文件 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)

代码运行但只生成一个空白文件。任何帮助将不胜感激。

4

1 回答 1

0

再添加一项设置:

settings.CloseOutput = True

最后你也错过了吗?

writer.WriteEndDocument()
writer.Flush()
writer.Close()
于 2013-09-04T13:29:02.177 回答