Problem making XML RPC call

Problem making XML RPC call

做个少女永远怀春 发布于 2021-11-25 字数 1294 浏览 843 回复 2 原文

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?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

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

评论(2

依 靠。 2022-06-07 2 楼

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

唔猫 2022-06-07 1 楼

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?