Answer the question
In order to leave comments, you need to log in
How to change Headers in CefSharp?
Purpose: to create a separate program for the site, i.e. so that the site can be opened with this program. To do this, you need to pass the referer header. The thing is that CefSharp does not give me the opportunity to do this, or I'm doing something wrong.
On startup, an exception is thrown:
"IRequest is read-only and cannot be modified. Check IRequest.IsReadOnly to guard against this exception."
using CefSharp;
using CefSharp.Handler;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NewDeaf
{
public partial class NewDeafForm : Form
{
public NewDeafForm()
{
InitializeComponent();
}
public ChromiumWebBrowser wb;
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
wb = new ChromiumWebBrowser("https://newdeaf.site")
{
RequestHandler = new ChromeBrowserRequestHandler()
};
WbPanel.Controls.Add(wb);
wb.Dock = DockStyle.Fill;
}
private void NewDeafForm_Load(object sender, EventArgs e)
{
InitializeChromium();
wb.Load("https://newdeaf.site");
wb.RequestHandler.OnBeforeBrowse(wb, null, null, Request.Create(), false, false);
}
}
class ChromeBrowserRequestHandler : RequestHandler
{
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
{
request.SetReferrer("https://KiIzEDPhB0.com", ReferrerPolicy.ClearReferrerOnTransitionCrossOrigin);
return false;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question