我已使用下面的代码成功连接到服务,但我需要将响应保存到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)
代码运行但只生成一个空白文件。任何帮助将不胜感激。
答案 0 :(得分:0)
再添加一个设置:
settings.CloseOutput = True
最后你也错过了吗?
writer.WriteEndDocument()
writer.Flush()
writer.Close()