C# 获取Get请求返回

        /// <summary>
/// 远程获取页面数据
/// </summary>
/// <param name="Url">地址</param>
/// <returns></returns>
public static string GetHttpData(string Url)
{
//string sException = null;
string sRslt = null;
WebResponse oWebRps = null;
WebRequest oWebRqst = WebRequest.Create(Url);
oWebRqst.Timeout = 50000;
//try
//{
oWebRps = oWebRqst.GetResponse();
//}
//catch (WebException e)
//{
// sException = e.Message.ToString();
// HttpContext.Current.Response.Write(sException);
//}
//catch (Exception e)
//{
// sException = e.ToString();
// HttpContext.Current.Response.Write(sException);
//}
//finally
//{
if (oWebRps != null)
{
StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), Encoding.UTF8);
sRslt = oStreamRd.ReadToEnd();
oStreamRd.Close();
oWebRps.Close();
}
//}
return sRslt;
}

  

上一篇:vi初接触


下一篇:JS中的NaN