asp.net远程获取文件代码

来源:互联网 发布:数据库阻塞 编辑:程序博客网 时间:2024/06/06 21:53
public 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();            Response.Write(sException);        }        catch (Exception e)        {            sException = e.ToString();            Response.Write(sException);        }        finally        {            if (oWebRps != null)            {                StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), Encoding.GetEncoding("UTF-8"));                sRslt = oStreamRd.ReadToEnd();                oStreamRd.Close();                oWebRps.Close();            }        }        return sRslt;    }

0 0
原创粉丝点击