【问题标题】:create XML and send over HTTP post创建 XML 并通过 HTTP post 发送
【发布时间】:2011-07-05 17:30:21
【问题描述】:

我正在使用 Litle 的支付系统,我必须创建一个 XML 文档,根据他们的 XSD 对其进行验证,然后通过 HTTP post 传输它。

有什么建议吗?

目前我正计划使用 XmlDocument 类来创建和验证 XML,并且仍在研究使用什么将其传输到服务器,并获取返回的响应(也是 XML 格式的)。

最好的方法是什么?

没有:没有基于 Web 服务的 API。只需手动格式化 XML 和帖子。尽管如果有一些库可以自动执行此操作,那将非常有帮助。

【问题讨论】:

    标签: .net asp.net xml e-commerce


    【解决方案1】:

    您可以使用WebClient 发送 HTTP 请求。

    using (var client = new WebClient())
    {
        client.Headers[HttpRequestHeader.ContentType] = "text/xml";
        // you could add any other HTTP request headers that the server expects
    
        // fetch the XML that you want to POST
        string xml = ...
        byte[] data = Encoding.UTF8.GetBytes(xml);
        // POST the XML to the given address
        byte[] result = client.UploadData("http://example.com", data);
    
        // TODO: process the result, for example load it in a XDocument
        using (var stream = new MemoryStream(result))
        using (var reader = XmlReader.Create(stream))
        {
            var doc = XDocument.Load(reader);
        }
    }
    

    【讨论】:

    • 它说:“出于安全原因,此 XML 文档中禁止使用 DTD。要启用 DTD 处理,请将 XmlReaderSettings 上的 ProhibitDtd 属性设置为 false 并将设置传递给 XmlReader.Create 方法。”然后添加: XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.ProhibitDtd = false;并将 XmlReader.Create 更改为 XmlReader.Create(stream, xmlReaderSettings)
    猜你喜欢
    • 2014-03-12
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多