C# 利用xmlhttp根据网址调用接口获取数据
2009-12-22 09:29
337 查看
利用xmlhttp根据网址调用接口获取数据
//引入com组件中的microsoft.xml.3.0代码public void GetDown(String Url)
{
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.Write(_xmlhttp.statusText);
Response.End();
//引入com组件中的microsoft.xml.3.0代码public void GetDown(String Url)
{
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.Write(_xmlhttp.statusText);
Response.End();
相关文章推荐
- C# 利用xmlhttp根据网址调用接口获取数据
- C#编写webservice接口、调用以及解析数据
- 利用XMLHTTP无刷新获取数据
- C#微信开发之获取接口调用凭据
- 利用XMLHTTP无刷新获取数据
- ios进行restful接口调用和json数据利用自带NSJSONSerialization进行数据解析
- Post提交数据到接口或网址 获取返回数据
- C# 调用LDAP接口获取域用户信息
- (转) 在C#中使用WIA获取扫描仪数据(三、利用Filter处理图片)
- C#调用TeeChart显示数据,当放大时,怎样当前图表中获取X轴的最小值和最大值
- 模糊查询 根据接口获取联想数据 查询出来数据还可以继续输入
- C#利用反射动态调用DLL并返回结果,和获取程序集的信息
- C#Json数据反序列化为Dictionary并根据关键字获取指定的值
- 在小程序后端中转获取接口数据,绕过前端调用限制
- 如何利用POST数据到web页面接口(包括调用页面发送json数据和页面后台接受json数据)
- 根据IP地址获取地理位置(利用腾讯提供接口)
- 根据URL接口地址获取JSON数据
- 利用XMLHTTP 从其他页面获取数据
- 利用window.name+iframe跨域获取接口数据
- C#利用接口实现窗体间函数调用