XML RPC 调用时出现问题
我正在尝试隔离进行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果在保存 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?
我最终使用 http://www.xml-rpc.net/ 而不是自己编写。
I ended up using http://www.xml-rpc.net/ instead of writing my own.