在网上有一个 my.swf 文件,有2M左右,System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://www.xxxx.com/my.swf", "d:\\tmp\\my.swf");用以上方法,下载后的文件只有 9K,这是为什么?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxxx.com/my.swf");
HttpWebResponse response =(HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
int lenth=(int)response.ContentLength;
byte[] buf=new byte[lenth];
s.Read(buf,0,lenth);
FileStream file = new FileStream("d:\\tmp\\my.swf", FileMode.Create);
file.Write(buf, 0, buf.Length);
s.Close();
用以上方法,下载后的文件也只有9K.这个问题该如何解决呢?
client.DownloadFile("http://www.xxxx.com/my.swf", "d:\\tmp\\my.swf");用以上方法,下载后的文件只有 9K,这是为什么?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxxx.com/my.swf");
HttpWebResponse response =(HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
int lenth=(int)response.ContentLength;
byte[] buf=new byte[lenth];
s.Read(buf,0,lenth);
FileStream file = new FileStream("d:\\tmp\\my.swf", FileMode.Create);
file.Write(buf, 0, buf.Length);
s.Close();
用以上方法,下载后的文件也只有9K.这个问题该如何解决呢?
解决方案 »
- 怎么循环得到资源文件里面的图片啊
- vcredist_x86.exe安装时问题
- XNA,游戏加载的时候加载声音就会异常,麻烦帮解决下
- 请高手帮忙:C#如何设定当鼠标移到lable控件上时出现下划线?
- 如何在 aspx 页面下 添加 类似于 winform 下的 table control 控件?
- WinFrom lable 换行
- WinFrm备份数据库时如何得到安装程序所在的路径(希望指点)谢谢了
- 请教:SQLServer 全文检索的问题
- 求问c#做的绘图软件背景的白灰相间的方块能否去掉
- ASP.NET和短信猫 实现短信群发?请大家提供源代码或其他设计方案
- 关于用户记录算法 急!急!急!
- winfrom调用控制台vs自动编译!!??
要保证头信息没有错误 public void DownFile(string url, string Filename)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET"; request.Timeout = 300000;
request.KeepAlive = true;
request.AllowAutoRedirect = true; request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 2.0.50727; CIBA)"; request.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse webresponse = null;
try
{
webresponse = request.GetResponse() as HttpWebResponse;
if (webresponse != null)
{
Stream st = webresponse.GetResponseStream();
Stream so = new FileStream(Filename, FileMode.Create);
byte[] by = new byte[1024];
int osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
so.Write(by, 0, osize);
osize = st.Read(by, 0, (int)by.Length);
}
so.Close();
st.Close();
}
}
catch
{
}
finally
{
if (webresponse != null)
{
webresponse.Close();
webresponse = null;
}
if (request != null)
{
request.Abort();
request = null;
}
}
}
byte[] mbyte = new byte[100000];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
while (allmybyte > 0)
{
int m = str.Read(mbyte, startmbyte, allmybyte);
if (m == 0)
break;
startmbyte += m;
allmybyte -= m;
} FileStream fstr = new FileStream(DownFilePath, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(mbyte, 0, startmbyte);
str.Close();
fstr.Close();
现在一般的flash都有个播放器,然后缓冲数据的。