簡體   English   中英

具有Fiddler代理和HTTP身份驗證的C#PhantomJSDriver:未捕獲流量

[英]C# PhantomJSDriver with Fiddler proxy and HTTP authentication: traffic not captured

我正在嘗試導航到需要使用PhantomJSDriver進行身份驗證並將URL傳遞username:password的localhost站點上的應用程序。 為了捕獲響應代碼,我使用了Jim Evan的示例https://github.com/jimevans/WebDriverProxyExamples中的Fiddler代理。

PhantomJSDriver可以成功導航(使用NTLM /基本身份驗證),但是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/ 與身份驗證無關,而是從本地主機獲取流量。

解決方案是在URL中使用本地計算機名稱代替localhost。

我通過http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/找到了問題。 與身份驗證無關,而是從本地主機獲取流量。 我不確定為什么,但是使用PhantomJSDriver導航到本地url和Fiddler捕獲流量的組合似乎不起作用。

解決方案是使用本地機器名稱代替URL中的“本地主機”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM