ChromiumWebBrowser cerf设置header

 var urlValue = string.Format(url, key, id, dic);
                MessageBox.Show(urlValue);
                browser = new ChromiumWebBrowser(urlValue);
                browser.RequestHandler = new CustomRequestHandler();
                browser.Parent = panel1;
                browser.Dock = DockStyle.Fill;               
                browser.DownloadHandler = new DownloadHandler();


public class CustomResourceRequestHandler : ResourceRequestHandler
{
    protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
    {
        var headers = request.Headers;
        headers["User-Agent"] = "My User Agent";
        request.Headers = headers;

        return CefReturnValue.Continue;
    }
}

public class CustomRequestHandler : RequestHandler
{
    protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
    {
        return new CustomResourceRequestHandler();
    }
}

browser.RequestHandler = new CustomRequestHandler();


https://stackoverflow.com/questions/31250797/chromium-send-custom-header-info-on-initial-page-load-c-sharp

你可能感兴趣的:(vsto,c#)