带有Fiddler代理和HTTP身份验证的C#PhantomJSDriver:未捕获流量(C# PhantomJSDriver with Fiddler proxy and HTTP authenti

编程入门 行业动态 更新时间:2024-10-27 17:24:01
带有Fiddler代理和HTTP身份验证的C#PhantomJSDriver:未捕获流量(C# PhantomJSDriver with Fiddler proxy and HTTP authentication: traffic not captured)

我试图导航到localhost站点上的应用程序,该站点需要使用PhantomJSDriver进行身份验证并将用户名:密码传递到URL。 为了捕获响应代码,我使用了Jim Evan的示例https://github.com/jimevans/WebDriverProxyExamples中的Fiddler代理。

PhantomJSDriver成功导航(使用NTLM / Basic auth),但Fiddler不捕获流量。

public static int NavigateTo(this IWebDriver driver, string targetUrl, TimeSpan timeout, bool printDebugInfo) { int responseCode = 0; DateTime endTime = DateTime.Now.Add(timeout); SessionStateHandler responseHandler = delegate(Session targetSession) { if (targetSession.responseCode >= 300 && targetSession.responseCode < 400) { targetUrl = targetSession.GetRedirectTargetURL(); } else responseCode = targetSession.responseCode; }; // Attach the event handler, perform the navigation, and wait for // the status code to be non-zero, or to timeout. Then detach the // event handler and return the response code. FiddlerApplication.AfterSessionComplete += responseHandler; driver.Url = targetUrl; while (responseCode == 0 && DateTime.Now < endTime) { System.Threading.Thread.Sleep(100); } FiddlerApplication.AfterSessionComplete -= responseHandler; return responseCode; }

当使用具有相同应用程序的ChromeDriver以及不需要使用PhanotmJSDriver进行身份验证的网站时,我能够捕获流量。 它无法使用的唯一场景是PhantomJSDriver +身份验证网站。

更新:感谢Dead Link http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/, 我发现了这个问题。 这与身份验证无关,而是从localhost获取流量。

解决方案是使用本地计算机名称代替URL中的localhost。

I am trying to navigate to an application on a localhost site that requires authentication using PhantomJSDriver and passing username:password into the URL. In order to capture response codes I'm using a Fiddler proxy from Jim Evan's example https://github.com/jimevans/WebDriverProxyExamples.

PhantomJSDriver navigates successfully (using NTLM/Basic auth) but Fiddler doesn't capture the traffic.

public static int NavigateTo(this IWebDriver driver, string targetUrl, TimeSpan timeout, bool printDebugInfo) { int responseCode = 0; DateTime endTime = DateTime.Now.Add(timeout); SessionStateHandler responseHandler = delegate(Session targetSession) { if (targetSession.responseCode >= 300 && targetSession.responseCode < 400) { targetUrl = targetSession.GetRedirectTargetURL(); } else responseCode = targetSession.responseCode; }; // Attach the event handler, perform the navigation, and wait for // the status code to be non-zero, or to timeout. Then detach the // event handler and return the response code. FiddlerApplication.AfterSessionComplete += responseHandler; driver.Url = targetUrl; while (responseCode == 0 && DateTime.Now < endTime) { System.Threading.Thread.Sleep(100); } FiddlerApplication.AfterSessionComplete -= responseHandler; return responseCode; }

I was able to capture the traffic when using ChromeDriver with the same application and also for a website that didn't require authentication using PhanotmJSDriver. The only scenario it doesn't work in is PhantomJSDriver + authentication website.

Update: I discovered the issue thanks to Dead Link http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/ . It was nothing to do with authentication rather getting traffic from localhost.

The solution was to use the local machine name in place of localhost in the URL.

最满意答案

我发现这个问题归功于http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/ 。 这与身份验证无关,而是从localhost获取流量。 我不确定为什么,但似乎使用PhantomJSDriver导航到localhost url和Fiddler捕获流量的组合不起作用。

解决方案是使用本地MACHINE NAME代替URL中的“localhost”。

I discovered the issue thanks to http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/. It was nothing to do with authentication rather getting traffic from localhost. I'm not sure why, but it seems the combination of using PhantomJSDriver to navigate to a localhost url and Fiddler to capture the traffic did not work.

The solution was to use the local MACHINE NAME in place of 'localhost' in the URL.

更多推荐

本文发布于:2023-08-06 12:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   流量   PhantomJSDriver   Fiddler   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!