如题,利用System.Net.HttpWebRequest 和System.Net.HttpWebResponse 抓取一般网页的内容可以,可现在需要抓取本站的.aspx主页带session认证的html代码,系统报错
我的问题是如何能将session 和cookie得值一起送到服务器后正常获取需要认证的网页的html
解决方法只限于利用 System.Net.HttpWebRequest 和System.Net.HttpWebResponse 利用Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)可以抓取网页内容的所以就不用给出了
我的问题是如何能将session 和cookie得值一起送到服务器后正常获取需要认证的网页的html
解决方法只限于利用 System.Net.HttpWebRequest 和System.Net.HttpWebResponse 利用Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)可以抓取网页内容的所以就不用给出了
System.Net.CookieContainer cc = new System.Net.CookieContainer();
string postData = "uUsername=avoid&uPassword=123456";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sUrl);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
System.IO.Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length); newStream.Close(); request.CookieContainer = cc; System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
cc.Add(response.Cookies);
System.IO.Stream stream = response.GetResponseStream();
string sHtml = new System.IO.StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
Error en el servidor remoto: (404) No se encontró. (远端服务器发生错误 404,没有找到所需网页)Detalles de la excepción: System.Net.WebException: Error en el servidor remoto:
(404) No se encontró.Error de código fuente: 错误行
Línea 428: request.CookieContainer = cc
Línea 429:
Línea 430: Dim response As System.Net.HttpWebResponse = DirectCast(request.GetResponse(), System.Net.HttpWebResponse)Línea 431: cc.Add(response.Cookies)
Línea 432: Dim stream As System.IO.Stream = response.GetResponseStream()
Protected Sub __Firmar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles __Firmar.Click
Dim cc As New System.Net.CookieContainer()
Dim postData As String = "uUsername=comprador1&uPassword=2007jca1"
Dim encoding As New ASCIIEncoding()
Dim data As Byte() = encoding.GetBytes(postData) Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(System.Web.HttpContext.Current.Request.Url.AbsoluteUri.ToString), System.Net.HttpWebRequest)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = data.Length
Dim newStream As System.IO.Stream = request.GetRequestStream()
newStream.Write(data, 0, data.Length) newStream.Close() request.CookieContainer = cc Dim response As System.Net.HttpWebResponse = DirectCast(request.GetResponse(), System.Net.HttpWebResponse)
cc.Add(response.Cookies)
Dim stream As System.IO.Stream = response.GetResponseStream()
Dim sHtml As String = New System.IO.StreamReader(stream, System.Text.Encoding.[Default]).ReadToEnd()
End Sub
http://201.228.160.4/
在右上角有个 >> Ingreso de usuarios 字样
点击后 有login界面, 用户名comprador1, 密码 2007jca1 (主意小写)
进去 后你看看能不能截取下面 那个iframe里的东西谢谢了
首先用户确认一个表格 ->点签名选项 ->服务器截取当前表格的html 将其隐藏在一个hidden里面 返回给客户端
-> 客户端利用js和本机安装的秘钥对html进行签名后 提交给服务器
后面的验证什么的 就不说了,目前主要问题还是截取html code我尝试用了一下Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)的方法可以正确截取 html的代码,但问题是根本无法有效的给控件赋值
目前只能用
writer.Write(html.ToString.replace(",""")) 生改html 的东西,这么做感觉意义不大, 要求签名的页面很多,那么做的话工作量也 太大了不知道楼上的还有什么 可行的解决方法 来截取 当前 .aspx页面的html code不胜感激
http://blog.csdn.net/jinjazz/archive/2007/12/28/1996163.aspx
文件头 如下不知道是否可以和System.Net.HttpWebRequest 结合使用以获得当前页面的html code
POST /Adquisicion/publicaradquisicion.aspx?IdLC=336 HTTP/1.1
Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 1119
Content-Type: application/x-www-form-urlencoded
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-silverlight, */*
Accept-Encoding: gzip, deflate
Accept-Language: es-us
Cookie: NomUsuario=comprador1; ASP.NET_SessionId=3kwd3345z1wgulq5igap4gfm; IDUSUARIO=; IDEMPRESA=; IDORGC_W=; IDORGV_W=; IDORGC_M=; IDORGV_M=; origen=; SQLAUTHCOOKIE=05E2ED08DA6AC158C98AFB9D1C5D87053199E49222577425D4A18EF1FA9869F2674B0C83379161E1A8450C327146E6887DA45CC4363170AA323CC315545C540697CC2368979396226E8EA7439788B8756F05CBB1577FBF7582232AED0534DBF889967DFEF007CDB9EA6F43447198942CEB28929001A6994C139FB6102C43A375EE3D919A2320E47CAAEC72B495D8AAD3
Host: localhost:88
Referer: http://localhost:88/Adquisicion/publicaradquisicion.aspx?IdLC=336
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)
UA-CPU: x86