在.NET中使用XMLhttp下载文件,为什么在我在第一次下载文件时,可以得到数据.但是我在对服务器上的数据进行修改时,我下载下来文件的数据没有随着改变?只到重复运行的第3次,数据才会该变,这是为什么?
下面是我的程序:
string Url = "http://192.168.1.6/hneoms/xxx.txt";
string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);
string StringFilePath = Request.PhysicalApplicationPath;
if(!StringFilePath.EndsWith("/")) StringFilePath += "/";
MSXML2.XMLHTTP _XMLhttp = new MSXML2.XMLHTTPClass();
_XMLhttp.open("GET",Url,false,null,null);
_XMLhttp.send("");
if( _XMLhttp.readyState == 4 )
{
if(System.IO.File.Exists(StringFilePath + StringFileName))
System.IO.File.Delete(StringFilePath + StringFileName);
System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
w.Write((byte[])_XMLhttp.responseBody);
w.Close();
fs.Close();
Response.Write ("文件已经得到。<br><a href='../../" + Request.ApplicationPath + StringFileName +"' target='_blank'>");
Response.Write ("查看" + StringFileName + "</a>");
}
else
{
Response.End();
}
下面是我的程序:
string Url = "http://192.168.1.6/hneoms/xxx.txt";
string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);
string StringFilePath = Request.PhysicalApplicationPath;
if(!StringFilePath.EndsWith("/")) StringFilePath += "/";
MSXML2.XMLHTTP _XMLhttp = new MSXML2.XMLHTTPClass();
_XMLhttp.open("GET",Url,false,null,null);
_XMLhttp.send("");
if( _XMLhttp.readyState == 4 )
{
if(System.IO.File.Exists(StringFilePath + StringFileName))
System.IO.File.Delete(StringFilePath + StringFileName);
System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
w.Write((byte[])_XMLhttp.responseBody);
w.Close();
fs.Close();
Response.Write ("文件已经得到。<br><a href='../../" + Request.ApplicationPath + StringFileName +"' target='_blank'>");
Response.Write ("查看" + StringFileName + "</a>");
}
else
{
Response.End();
}
看一下该页面是否有页面缓存,或者看看有没有数据缓存