XmlWriter无法直接写入URL,因此我应该如何将XML发送到URL?

时间:2013-05-30 20:59:07

标签: xml vb.net

正如问题所述,我尝试将XmlWriter与定义为与共享文档站点关联的http地址的目标一起使用。如何使用XmlWriter或不使用XmlWriter

在那里发送文件
    Dim resolver As XmlUrlResolver = New XmlUrlResolver()
    resolver.Credentials = CredentialCache.DefaultCredentials

    Dim doc As New XmlDocument
    doc.XmlResolver = resolver

    Dim feedWriter As XmlWriter = XmlWriter.Create("URL")

    Select Case format
        Case FeedFormats.Atom
            Response.ContentType = "application/rss+xml"

            Dim atomFormatter As New Atom10FeedFormatter(feed)
            atomFormatter.WriteTo(feedWriter)
        Case FeedFormats.Rss
            Response.ContentType = "application/atom+xml"

            Dim rssFormatter As New Rss20FeedFormatter(feed)
            rssFormatter.WriteTo(feedWriter)
    End Select

    doc.Save(feedWriter)

    feedWriter.Close()

这是一个片段,我没有添加我的案例或提要声明,但这是不必要的。我想这应该用输出流完成,但我不知道如何做到这一点。

1 个答案:

答案 0 :(得分:1)

以下是完全未经测试的:

Public Sub WriteXmlToUrl(url As Uri)
    Dim request AS HttpWebRequest = CTYPE(WebRequest.Create(url), HttpWebRequest)
    request.Method = "POST"
    request.ContentType = "application/xml"
    Using stream = request.GetRequestStream
        Using writer = XmlWriter.Create(stream)
            rem Write your Xml
        End Using
    End Using
End Sub