//发送获取xml请求 public static string SentRequest(String url) { HttpWebRequest req = WebRequest.CreateHttp(url); req.Method = "GET"; HttpWebResponse resp = req.GetResponse() as HttpWebResponse; Stream stream = resp.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(resp.CharacterSet)); String json = reader.ReadToEnd(); stream.Close(); return json; } //获取xml转化格式 public static string GetXmlStr(string url) { string jsonstr = SentRequest(url); string json1 = jsonstr.Replace("<", "<"); string json2 = json1.Replace(">", ">"); return json2; }
string strXml = WebService.GetXmlStr(url); List<Model> ls = new List<Model>(); if (strXml.Contains("系统标识错误")) { ls = null; } else { XmlDocument xx = new XmlDocument(); xx.LoadXml(strXml); XmlNodeList xxlist = xx.GetElementsByTagName("xkxx"); foreach (XmlNode xxNode in xxlist) { Model model = new Model(); XmlNodeList childlist = xxNode.ChildNodes; model .name= childlist[0].InnerText; ls.Add(model); } ViewBag.UserModel= ls; }
时间: 2024-11-10 03:06:31