如何在c#中捕获javascript HTTP重定向? [英] How to capture javascript HTTP redirection in c#?

查看:154
本文介绍了如何在c#中捕获javascript HTTP重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究跟踪重定向的实用程序。 HTTP重定向可通过以下c#方法很好地处理:

I am working on a utility that track redirections. HTTP redirections are pretty well handled by the following c# methods:


  • HttpWebRequest

  • HttpWebResponse

  • WebHeaderCollection(提交位置)

下一步是在网址到最后的网址中包含javascript重定向页。

Next step is to include javascript redirections in a url journey to the final page.


  1. 如何在c#中捕获这种类型的重定向?

  2. 是否还有其他类型的重定向需要考虑?


推荐答案

如果您使用嵌入式JavaScript引擎并创建模拟DOM和javascript apis / prototypes的一些更常访问的方面的数据模型,那么您可以加载页面,执行任何和所有javascript代码并让你的window.location属性setter在设置时触发一个事件,然后像往常一样关注该url。这允许您处理计算值以及您的标准

If you use an embedded javascript engine and create data models that mock up some of the more commonly accessed aspects of the DOM and the javascript apis/prototypes, then you could load the page, execute any and all javascript code and have your window.location property setter fire an event when it gets set, then just follow that url as normal. This allows you to handle computed values as well as your standard

window.location = "/home";

C#的嵌入式javascript引擎没有短缺,这里只是我发现的几个非常好:

There are no short supply of embedded javascript engines for C#, here are just a few that I find to be really good:

Javascript.Net - 使用谷歌的V8引擎。非常容易集成到应用程序中。唯一的缺点是在您的应用程序中保留一个非托管DLL。
https://github.com/JavascriptNet/Javascript.Net

Javascript.Net - Uses Google's V8 engine. Really easy to integrate in an application. Only downside-ish is keeping an unmanaged DLL with your application. https://github.com/JavascriptNet/Javascript.Net

Jint (.Net的Javascript Interpreter) - 非常好。完全托管的代码。同样,易于集成到应用程序中。
http://jint.codeplex.com/

Jint (Javascript Interpreter for .Net) - Really good. Fully managed code. Again, easy to integrate within an application. http://jint.codeplex.com/

这里的真正关键是模拟浏览器通常创建的内容。

The real key here is mocking up what is normally created by a browser.

这篇关于如何在c#中捕获javascript HTTP重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆