如何从提供xml的URL获取xml响应? [英] How to get xml response from a URL that serves xml?
问题描述
我有一个mvc 4休息服务,现在我有ac桌面应用程序,我想通过该服务使用,我在服务中有一个'测试'功能,现在我想从应用程序调用它得到xml文档中的响应,我该怎么做?
例如url是:http:// localhost:3466 / api / acp / test
,回复是:图片
有什么想法吗?我成功了唯一的字符串成功执行,我删除的代码,因为它没有帮助,我需要在xml对象中有完整的响应。 tnx提前。
I have a mvc 4 rest service, now i have a c# desktop application, which i want to use via that service, and i have a 'test' function inside the service, now i want to call it from the application and get the response in xml document, how can i do this?
for example the url is: "http://localhost:3466/api/acp/test"
and the response is: image
any idea? i managed to the only the string "successfully executed", with a code that i deleted because its no help, i need to have the full response in xml object. tnx in advance.
推荐答案
试过这个:
just tried this:
static void testGetXmlDocFromWebRequest()
{
string response = string.Empty;
string url = "your-url";
WebRequest request = WebRequest.Create(url);
try
{
using (StreamReader streamIn = new StreamReader((request.GetResponse()).GetResponseStream()))
{
response = streamIn.ReadToEnd();
streamIn.Close();
}
}
finally
{
request.Abort();
}
XDocument xDoc = XDocument.Parse(response);
}
并且它有效。摘自:此处
这篇关于如何从提供xml的URL获取xml响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!