【发布时间】:2009-12-30 20:38:54
【问题描述】:
我需要调用一个有 javascript 的网页。在页面底部我有以下内容:
<noscript>
<p>Javascript is not supported or enabled.</p>
</noscript>
当我像这样发出 HttpWebRequest 请求时,很明显页面上的 javascript 没有执行。
Dim req As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(New Uri(url)), System.Net.HttpWebRequest)
' Add the current authentication cookie to the request
Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName)
Dim authenticationCookie As New System.Net.Cookie(FormsAuthentication.FormsCookieName, cookie.Value, cookie.Path, HttpContext.Current.Request.Url.Authority)
req.CookieContainer = New System.Net.CookieContainer()
req.CookieContainer.Add(authenticationCookie)
req.MediaType = "PRINT"
req.Method = "GET"
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
Dim res As System.Net.WebResponse = req.GetResponse()
我能做什么?如果 javascript 没有运行,响应对我没有用。我想将输出转换为 PDF。我想我需要一种方法来执行响应中包含的 javascript,但要在浏览器之外执行。
谢谢。
【问题讨论】:
标签: asp.net javascript httpwebrequest