本文介绍了Awesomium,更改用户代理和推荐人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 awesomium.我想了解如何更改用户代理和推荐人.例如,我需要初始化 5 个 istance o awesomium webcontrol,对于它们中的每一个,我需要不同的用户代理和不同的引用.这是我的简单代码

 private void newbrowser(){browser = new Awesomium.Windows.Forms.WebControl();browser.Paint += browser_Paint;browser.Location = new System.Drawing.Point(1, 1);browser.Name = "webControl";browser.Size = new System.Drawing.Size(1024, 768);browser.Source = new System.Uri("https://www.google.com/", System.UriKind.Absolute);浏览器.TabIndex = 0;}void browser_Paint(对象发送者,PaintEventArgs e){browser.Paint -= browser_Paint;System.Collections.Specialized.NameValueCollection myCol =新 System.Collections.Specialized.NameValueCollection();myCol.Add("Referer", "http://www.yahoo.com");browser.SetHeaderDefinition("MyHeader", myCol);browser.AddHeaderRewriteRule("http://*", "MyHeader");}private void button1_Click(object sender, EventArgs e){新浏览器();}

这两行报错

 browser.SetHeaderDefinition("MyHeader", myCol);browser.AddHeaderRewriteRule("http://*", "MyHeader");

错误 1 ​​'Awesomium.Windows.Forms.WebControl' 不包含'SetHeaderDefinition' 的定义错误 1 ​​'Awesomium.Windows.Forms.WebControl' 不包含'AddHeaderRewriteRule' 的定义

感谢您的帮助

解决方案

您需要设置管理您的 WebControl 的 WebCore 的用户代理.这必须在您创建 WebControl 之前完成.

public WebForm(){如果(!WebCore.IsRunning)WebCore.Initialize( new WebConfig() { UserAgent = "YourUserAgent" } );初始化组件();}

I just started to use awesomium.I wanted to understand how to change user-agent and referrer.i need for example to initialize 5 istance o awesomium webcontrol and for each of them i need different user-agent and different referrer.this is my simple code

        private void newbrowser()
    {
            browser = new Awesomium.Windows.Forms.WebControl();
            browser.Paint += browser_Paint;
            browser.Location = new System.Drawing.Point(1, 1);
            browser.Name = "webControl";
            browser.Size = new System.Drawing.Size(1024, 768);
            browser.Source = new System.Uri("https://www.google.com/", System.UriKind.Absolute);
            browser.TabIndex = 0;

    }

    void browser_Paint(object sender, PaintEventArgs e)
    {
        browser.Paint -= browser_Paint;

        System.Collections.Specialized.NameValueCollection myCol =
            new System.Collections.Specialized.NameValueCollection();
        myCol.Add("Referer", "http://www.yahoo.com");

        browser.SetHeaderDefinition("MyHeader", myCol);
        browser.AddHeaderRewriteRule("http://*", "MyHeader");
    }
    private void button1_Click(object sender, EventArgs e)
    {
        newbrowser();
    }

these 2 lines give an error

        browser.SetHeaderDefinition("MyHeader", myCol);
        browser.AddHeaderRewriteRule("http://*", "MyHeader");

thanks for the help

解决方案

You need to set the user agent of the WebCore that governs your WebControl. This must be done before you create your WebControl.

public WebForm()
{
    if ( !WebCore.IsRunning )
        WebCore.Initialize( new WebConfig() { UserAgent = "YourUserAgent" } );

    InitializeComponent();
}

这篇关于Awesomium,更改用户代理和推荐人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 23:28