首页 新闻 搜索 专区 学院

WinForm 下载 web站点中的txt

0
[已关闭问题] 关闭于 2012-12-28 11:13

string serverPath="http://127.0.0.1/file/order?id=10";

HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(serverPath);
                httpWebRequest.Headers.Add("Translate:f");
                httpWebRequest.Credentials = CredentialCache.DefaultCredentials;

                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                Stream stream = null;
                stream = httpWebResponse.GetResponseStream();
                int fileSize = (int)httpWebResponse.ContentLength;

                byte[] buffer = new byte[fileSize];
                FileStream fileStream = File.Open(localDownLoadPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                int length = stream.Read(buffer, 0, fileSize);
                long total = length;
                while (length > 0)
                {
                    fileStream.Write(buffer, 0, length);
                    length = stream.Read(buffer, 0, fileSize);
                    total += length;
                }

                fileStream.Close();

 

网址采用了伪静态,下载不了文件,不知有何办法?

king2003的主页 king2003 | 初学一级 | 园豆:161
提问于:2012-11-20 15:58
< >
分享
所有回答(2)
0

webclient.down,......试试

chenping2008 | 园豆:9836 (大侠五级) | 2012-11-20 16:40
0

 WebClient client = new WebClient();

client.DownloadString(URL);

在 水 一 方 | 园豆:1097 (小虾三级) | 2012-11-21 17:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册