Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Cannot programmatically set referrer in CefSharp

Alberto Pastore:

I'm trying to force a specific Referrer Header when loading a URL in CefSharp OffScreen. I've followed examples and suggestions which indicate to do that inside IRequestHandler.OnBeforeResourceLoad. Nothing happens, the referrer header is not sent in the request.

Here is a snippet from my tests:


public class CefWorker: IRequestHandler
{
ChromiumWebBrowser Browser;
string InitialUrl;

// ... constructor and other methods here ...

public void Run()
{
InitialUrl = "https://www.msoft.it/about/chi-siamo/";

CefSettings Settings = new CefSettings()
{
WindowlessRenderingEnabled = true,
LogSeverity = LogSeverity.Disable
};
Settings.SetOffScreenRenderingBestPerformanceArgs();
Cef.Initialize(Settings, performDependencyCheck: Program.Settings.CheckCefDependencies, browserProcessHandler: null);
Browser = new ChromiumWebBrowser()
{
RequestHandler = this
};
Browser.BrowserInitialized += (o, e) => { Browser.Load(InitialURL); };
}

public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
if (request.Url == InitialUrl) {
request.SetReferrer("https://www.msoft.it/", ReferrerPolicy.Always);

// tried also this but it won't work
// request.Headers["Referer"] = "https://www.msoft.it/";

// this header is present in the request
request.Headers["X-MyCustomHeader"] = "My-Custom-Value";
}

return CefReturnValue.Continue;
}
}

When I dump the headers on server side, I can find

X-MyCustomHeader: My-Custom-Value

but there is no trace of Referer:

I'm testing this using CefSharp 63.0.0-pre02. What am I doing wrong?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Cannot programmatically set referrer in CefSharp

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×