这个格式的xml文件的url怎么下载(https://www.test.com/downfile?w=AFKSDFSLGFD-SDFE)
错误已经在代码中标出。
private void downfile()
{
string url= "https://www.test.com/downfile?w=AFKSDFSLGFD-SDFE ";
string FileName;
WebClient DownFile = new WebClient();
long fbytes;
if (url != " ")
{
FileName = @ "c:\save.xml ";
if (FileName != " ")
{
//取得文件大小
WebRequest wr_request = WebRequest.Create(url);
WebResponse wr_response = wr_request.GetResponse();
fbytes = wr_response.ContentLength;
wr_response.Close();
//开始下载数据
Stream strm = DownFile.OpenRead(url);//报错为找不到文件
StreamReader reader = new StreamReader(strm);
byte[] mbyte = new byte[fbytes];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
while (fbytes > 0)
{
int m = strm.Read(mbyte, startmbyte, allmybyte);
if (m == 0) break;
startmbyte += m;
allmybyte -= m;
}
FileStream fstrm = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
fstrm.Write(mbyte, 0, startmbyte);
strm.Close();
fstrm.Close();
}
}