获取远程xml数据-表结构

前端之家收集整理的这篇文章主要介绍了获取远程xml数据-表结构前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<span style="white-space:pre">	</span>/// <summary>
        /// 获取远程接口数据-表结构
        /// </summary>
        /// <param name="target">目标接口</param>
        /// <param name="ResponseTimeoutSeconds">响应超时时间(单位秒)</param>
        /// <param name="ReadWriteTimeoutSeconds">读写流超时时间(单位秒)</param>
        /// <returns>数据表结果集</returns>
        public static DataSet DownLoadRemoteData(string target,int ResponseTimeoutSeconds,int ReadWriteTimeoutSeconds)
        {
            DataSet ds = new DataSet();
            try
            {
                HttpWebRequest Request = System.Net.WebRequest.Create(target) as HttpWebRequest;
                Request.Method = "Get";
                //设置超时时间
                Request.Timeout = ResponseTimeoutSeconds * 1000;
                Request.ReadWriteTimeout = ReadWriteTimeoutSeconds * 10000;
                using (StreamReader responseReader = new StreamReader(Request.GetResponse().GetResponseStream(),Encoding.GetEncoding("gb2312")))
                {
                    XmlTextReader xmlReader = new XmlTextReader(responseReader);
                    ds.ReadXml(xmlReader);
                }
            }
            catch
            {
                ds = null;
            }
            return ds;
        }

猜你在找的XML相关文章