亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#實(shí)現(xiàn)HTTP下載文件的方法

 更新時(shí)間:2014年11月04日 09:10:10   投稿:shichen2014  
這篇文章主要介紹了C#實(shí)現(xiàn)HTTP下載文件的方法,包括了HTTP通信的創(chuàng)建、本地文件的寫(xiě)入等,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)HTTP下載文件的方法。分享給大家供大家參考。

主要實(shí)現(xiàn)代碼如下:

復(fù)制代碼 代碼如下:
/// <summary>
/// Http下載文件
/// </summary>
public static string HttpDownloadFile(string url, string path)
{
    // 設(shè)置參數(shù)
    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

    //發(fā)送請(qǐng)求并獲取相應(yīng)回應(yīng)數(shù)據(jù)
    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
    //直到request.GetResponse()程序才開(kāi)始向目標(biāo)網(wǎng)頁(yè)發(fā)送Post請(qǐng)求
    Stream responseStream = response.GetResponseStream();

    //創(chuàng)建本地文件寫(xiě)入流
    Stream stream = new FileStream(path, FileMode.Create);

    byte[] bArr = new byte[1024];
    int size = responseStream.Read(bArr, 0, (int)bArr.Length);
    while (size > 0)
    {
        stream.Write(bArr, 0, size);
        size = responseStream.Read(bArr, 0, (int)bArr.Length);
    }
    stream.Close();
    responseStream.Close();
    return path;
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論