XML RPC 调用时出现问题

发布于 2024-07-18 06:31:39 字数 1122 浏览 8 评论 0原文

我正在尝试隔离进行 XML RPC 调用时遇到的问题:

XDocument doc = new XDocument();
doc.Add(new XElement("methodCall",
        new XElement("methodName", "send"),
        new XElement("params",
            new XElement("param", new XElement("value", new XElement("string", this.ApiKey))),
            new XElement("param", new XElement("value", new XElement("string", this.FromAddress))),
            new XElement("param", new XElement("value", new XElement("string", recipient))),
            new XElement("param", new XElement("value", new XElement("string", contents)))  
        )
    )
);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://urlremoved");
req.ContentType = "text/xml";
req.Method = "POST";

XmlTextWriter writer = new XmlTextWriter(req.GetRequestStream(), Encoding.UTF8);
doc.Save(writer);

HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();

这只是停止并且永远不会超时(即使我在 req.TimeOut 和 req.ReadWriteTimeout 上设置了超时)。 我删除了 url,主要是为了将注意力集中在代码上。

代码中是否有任何问题会阻止进行此调用?

I'm trying isolate a problem I'm having making an XML RPC call:

XDocument doc = new XDocument();
doc.Add(new XElement("methodCall",
        new XElement("methodName", "send"),
        new XElement("params",
            new XElement("param", new XElement("value", new XElement("string", this.ApiKey))),
            new XElement("param", new XElement("value", new XElement("string", this.FromAddress))),
            new XElement("param", new XElement("value", new XElement("string", recipient))),
            new XElement("param", new XElement("value", new XElement("string", contents)))  
        )
    )
);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://urlremoved");
req.ContentType = "text/xml";
req.Method = "POST";

XmlTextWriter writer = new XmlTextWriter(req.GetRequestStream(), Encoding.UTF8);
doc.Save(writer);

HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();

This just stalls and never times out (even if I set timeouts on req.TimeOut and req.ReadWriteTimeout). I removed the url, mostly to keep the focus on just the code.

Is there anything wrong with the code that would prevent this call from being made?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⊕婉儿 2024-07-25 06:31:39

如果在保存 XML 后调用 writer.Flush(); 会发生什么情况?

我不确定为什么这不会超时,但也许它不会超时,因为由于写入被缓冲而没有发出请求?

What happens if you call writer.Flush(); after you save the XML?

I'm not sure why this doesn't time out, but maybe it doesn't time out as no request is being made due to the fact that writing is buffered?

沫尐诺 2024-07-25 06:31:39

我最终使用 http://www.xml-rpc.net/ 而不是自己编写。

I ended up using http://www.xml-rpc.net/ instead of writing my own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文