cefsharp设置网页接受语言Accept-Language

时间:2024-01-10 10:43:56

1.设置浏览器的请求控制器

webView.RequestHandler = new RequestHandler();

2.新建RequestHandler类继承IRequestHandler接口,实现方法OnBeforeResourceLoad

   /// <summary>
/// 资源加载之前事件(请求还未进入服务器)
/// </summary>
/// <param name="browser"></param>
/// <param name="requestResponse"></param>
/// <returns></returns>
public bool OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse)
{
IDictionary<string, string> headers = requestResponse.Request.GetHeaders();
headers.Add("Accept-Language", "zh,zh-cn,zh-tw");
requestResponse.Request.SetHeaders(headers);
return false;
}