【问题标题】:How to send xml to XML-RPC web service如何将 xml 发送到 XML-RPC Web 服务
【发布时间】:2014-04-10 18:24:15
【问题描述】:

C# 中的 .NET MVC 4.5 来自 Charles Cook 的 xml-rpc.net 库

试图用 xml-rpc 攻击第 3 方供应商。我需要向他们发送一些格式如下的 xml:

<?xml version='1.0' encoding='iso-8859-1'?> 
<QuoteRequest> 
    <User_ID>XXXXXXXX</User_ID> 
    <State>AL</State> 
    <Zip_Code>35201</Zip_Code> 
    <Applicant_Gender>Male</Applicant_Gender> 
    <Applicant_Age>30</Applicant_Age> 
    <Plan_ID>10</Plan_ID>
</QuoteRequest>

到目前为止我的努力:

var quoteRequest = new XmlRpcStruct();
var quoteRequestSpecs = new XmlRpcStruct();
quoteRequestSpecs.Add("Plan_ID", "10");
//add in other bits of xml here...user id, state, zip code, etc

quoteRequest.Add("QuoteRequest", quoteRequestSpecs);

var proxy = XmlRpcProxyGen.Create<IQuoteRequest>();
proxy.Url = "http://myfakeurl.com"
var response = proxy.QuoteRequest(quoteRequest);

IQuoteRequest 如下所示:

public interface IQuoteRequest : IXmlRpcProxy
{
    [XmlRpcMethod("QuoteRequest")]
    string QuoteRequest(XmlRpcStruct request);
}

我的服务很好,但我得到的只是以下内容:

"&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;&lt;QuoteResult&gt;&lt;Error&gt;&lt;Message&gt;Incorrect Plan ID.#&lt;/Message&gt;&lt;/Error&gt;&lt;/QuoteResult&gt;"

重要部分:“不正确的计划 ID”。

是的,我知道我使用了正确的计划 ID。

如果我根本不附加任何信息而只是通过一个空的 XmlRpcStruct 发送,我会收到相同的消息,所以我认为我的数据没有被发送。

【问题讨论】:

    标签: .net xml asp.net-mvc xml-rpc xml-rpc.net


    【解决方案1】:

    最终只需要传递一个字符串,而不是实际的 xml。

    var quoteRequest = "<QuoteRequest><User_ID>XXXXXXXXX</User_ID><State>TX</State><Zip_Code>75251</Zip_Code><Applicant_Gender>Male</Applicant_Gender><Plan_ID>10</Plan_ID></QuoteRequest>";
    
    var proxy = XmlRpcProxyGen.Create<IQuoteRequest>();
    proxy.Url = "http://myfakeurl.com"
    var response = proxy.QuoteRequest(quoteRequest);
    

    IQuoteRequest 看起来像:

    public interface IQuoteRequest : IXmlRpcProxy
    {
        [XmlRpcMethod("QuoteRequest")]
        string QuoteRequest(string request);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-06-16
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多