c# cefsharp browser trying to set proxy [closed]

送分小仙女□ 提交于 2020-06-08 19:11:11

问题


I'm not very good with CefSharp browsers so I need some outside help on this.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using System.Runtime.InteropServices;
using Microsoft.Win32;

 namespace WindowsFormsApplication7
{
    public partial class debug : Form
    {
        public ChromiumWebBrowser browser;

        public debug()
        {
            InitializeComponent();
            InitBrowser();
        }


        private void debug_Load(object sender, EventArgs e)
        {

        }

        public void InitBrowser()
        {
            Cef.Initialize(new CefSettings());
            browser = new ChromiumWebBrowser("https://whatismyipaddress.com/");     
            this.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;
            CefSettings cfsettings = new CefSettings();
            cfsettings.CefCommandLineArgs.Add("proxy-server", "200.29.191.149:3128");
            cfsettings.UserAgent = "My/Custom/User-Agent-AndStuff";
            Cef.Initialize(cfsettings);


        }

    }
}

This is my current code. I want it to use a proxy and I have been Googling for the past 3 hours now. It's getting late, so I hope someone can help me insert the proxy in there.


回答1:


If you are using a proxy type different "http", you must set it in proxy-schema e.g. as shown following

cfsettings.CefCommandLineArgs.Add("proxy-server", "socks5://200.29.191.149:3128");

You can read more in CEF3 Documentation




回答2:


You double set CefSettings. You must first configure. Configure is once in project and it should be before first call InitializeComponent() in your application.

public debug()
{
   Configure();
   InitializeComponent();
   CreateNewBrowser();
}

public void Configure()
{
   CefSettings cfsettings = new CefSettings();
   cfsettings.CefCommandLineArgs.Add("proxy-server", "200.29.191.149:3128");
   cfsettings.UserAgent = "My/Custom/User-Agent-AndStuff";
   Cef.Initialize(cfsettings);
}

public void CreateNewBrowser()
{
   browser = new ChromiumWebBrowser("https://whatismyipaddress.com/");     
   this.Controls.Add(browser);
   browser.Dock = DockStyle.Fill;     
}



回答3:


I have same trouble with SefSharp3. I launch CEF3 with same configurations

--proxy-server=...

and it works fine. I think it is a bug. And CefSharp3 have so much bugs I will use C++ CEF sources.



来源:https://stackoverflow.com/questions/43483645/c-sharp-cefsharp-browser-trying-to-set-proxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!