C \ # 노트 (19) HTTP 다운로드 실현

1837 단어 c#
//url     ,path       
public static string HttpDownload(string url, string path)
        {
            //     
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            //             
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            //  request.GetResponse()            Post  
            Stream responseStream = response.GetResponseStream();

            //         
            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;
        }

좋은 웹페이지 즐겨찾기