从 PAC 文件获取数据

发布于 2024-09-26 11:38:09 字数 62 浏览 1 评论 0原文

是否可以从 .Net Windows 应用程序执行 PAC 文件中的 Javascript 以返回代理服务器?

Is it possible to execute the Javascript in a PAC file from a .Net windows application to return the proxy server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2024-10-03 11:38:09

Since a proxy auto-config file is just a JavaScript source file, and you need to call a method in it, you could use the JScript .NET compiler (available in code via the JScriptCodeProvider) and/or interpreter (via JScriptEvaluate).

Compiler: Here's sample code to compile JScript .NET code to a class, and then call a method on that class, which might be a good fit for what you're looking for. Note that it uses Reflection, so it might give you troubles if you're in a partial-trust environment like ASP.NET. I'm not sure whether the Reflection is required for this kind of access, or if it's just an implementation detail; if that's an issue for you, you could research it further, or you could use the interpreter instead.

Interpreter: Here's an example that interprets JScript code using Microsoft.JScript.Eval.JScriptEvaluate. Since your PAC file is defining one or more functions, it won't return anything useful. You would need to append a line at the end that calls FindProxyForURL with the arguments you want; then you could evaluate that entire string and get your result. Or it's possible that you could eval the PAC file, which would declare the function, and then you could eval a call to that function (I haven't used JScriptEvaluate so I don't know whether globals carry over from one call to the next).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文