如何获取动态页的内容 大家好,请问asp.net如何获取网站中任一页面的前台http代码? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ...using System.Net;... public static string GetWebContent(string Url) { string strResult = ""; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); //声明一个HttpWebRequest请求 request.Timeout = 30000; //设置连接超时时间 request.Headers.Set("Pragma", "no-cache"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream streamReceive = response.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("GB2312"); StreamReader streamReader = new StreamReader(streamReceive, encoding); strResult = streamReader.ReadToEnd(); } catch{} return strResult; } private string getResult(string url) { HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(url); HttpWReq.KeepAlive = false; HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse(); String ver = HttpWResp.ProtocolVersion.ToString(); HttpWResp.Close(); return ver; }也是从论坛上得到的报错如下:异常详细信息: System.InvalidCastException: 无法将类型为“System.Net.FileWebRequest”的对象强制转换为类型“System.Net.HttpWebRequest”。请问该怎么解决? 首先添加引用 MSXML2.dll public static string aa(string url) { MSXML2.XMLHTTP26 oxmlHttp = new MSXML2.XMLHTTP26(); oxmlHttp.open("Get",url,false); oxmlHttp.send("0"); //oxmlHttp.readyState = 4; if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200) { return oxmlHttp.responseText.ToString(); } return ""; } public static string aa(string url) { MSXML2.XMLHTTP26 oxmlHttp = new MSXML2.XMLHTTP26(); oxmlHttp.open("Get",url,false,"user","pwd"); oxmlHttp.send("0"); if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200) { return oxmlHttp.responseText.ToString(); } return ""; } 找不到类型或命名空间名称“MSXML2”(是否缺少 using 指令或程序集引用?)需要引用什么程序集? System.Runtime.InteropServices.COMException: 无效的语法 这一行 oxmlHttp.send("0"); 报错 System.Runtime.InteropServices.COMException: 无效的语法 这一行 oxmlHttp.send("0"); 报错 首先添加引用 MSXML2.dll,然后 using System;using System.Web;using MSXML2;... /// <summary> /// 伪造http_referer /// </summary> /// <param name="url">需要访问的页面路径</param> /// <param name="dns">目标网站域名</param> /// <returns></returns> public static string setReferer(string url, string dns) { MSXML2.XMLHTTP26 oxmlHttp = new MSXML2.XMLHTTP26(); oxmlHttp.open("Get",url,false,"user","pwd"); oxmlHttp.setRequestHeader("Referer", dns);//如果不需要伪造http_referer,把这个去掉号了 oxmlHttp.send("0"); if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200) { return oxmlHttp.responseText.ToString(); } return ""; }... 怎么不让自动回复 系统邮件 做.net的困惑 asp.net控件哪有好的皮肤和外观可以下载? 问个问题。js找中如何找到tr里面某一控件的id。 在线等:求一打开文件时显示的进度条 关于datareader的异常处理问题,高手请进。 希望提供一个不用数据库存储数据的方法谢谢 身份验证问题 请教关于DataGrid中使用CheckBox的问题! 我用VS的向导制作了一个数据集,现在怎么在可视界面中指定DATAGRID的数据源到以上数据集? 如何用javascript设置或更改select中的option的样式 vs 2008 感冒了!!
using System.Net;
... public static string GetWebContent(string Url)
{
string strResult = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//声明一个HttpWebRequest请求
request.Timeout = 30000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("GB2312");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
}
catch{}
return strResult;
}
{
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(url);
HttpWReq.KeepAlive = false;
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
String ver = HttpWResp.ProtocolVersion.ToString();
HttpWResp.Close();
return ver;
}也是从论坛上得到的
报错如下:
异常详细信息: System.InvalidCastException: 无法将类型为“System.Net.FileWebRequest”的对象强制转换为类型“System.Net.HttpWebRequest”。
请问该怎么解决?
{
MSXML2.XMLHTTP26 oxmlHttp = new MSXML2.XMLHTTP26();
oxmlHttp.open("Get",url,false);
oxmlHttp.send("0");
//oxmlHttp.readyState = 4;
if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200)
{
return oxmlHttp.responseText.ToString();
}
return "";
}
public static string aa(string url)
{
MSXML2.XMLHTTP26 oxmlHttp = new MSXML2.XMLHTTP26();
oxmlHttp.open("Get",url,false,"user","pwd");
oxmlHttp.send("0");
if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200)
{
return oxmlHttp.responseText.ToString();
}
return "";
}
需要引用什么程序集?
这一行 oxmlHttp.send("0"); 报错
这一行 oxmlHttp.send("0"); 报错
using System.Web;
using MSXML2;
...
/// <summary>
/// 伪造http_referer
/// </summary>
/// <param name="url">需要访问的页面路径</param>
/// <param name="dns">目标网站域名</param>
/// <returns></returns>
public static string setReferer(string url, string dns)
{
MSXML2.XMLHTTP26 oxmlHttp = new MSXML2.XMLHTTP26();
oxmlHttp.open("Get",url,false,"user","pwd");
oxmlHttp.setRequestHeader("Referer", dns);//如果不需要伪造http_referer,把这个去掉号了
oxmlHttp.send("0");
if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200)
{
return oxmlHttp.responseText.ToString();
}
return "";
}
...