如何实现ResourceInterceptor Awesomium 1.7.1如何实现、ResourceInterceptor、Awesomium

2023-09-05 03:49:11 作者:纪念我们的曾经i

所以,我已经看到了这个问题,在此线程

so, i've seen this question on this thread

Awesomnium帖子参数

基本上,我想知道我可以实现资源拦截,因为我无法找到它..我还使用C#和我通过对象浏览器搜索,并没有发现该类...

basically i want to know how i can implement the Resource Interceptor, cause i can't find it.. i'm also using c# and i search through the object browser and didn't find the class...

这是我的code ..或多或少是相同的线程以上

this is my code.. more or less is the same as thread above

public class CustomInter : ResourceInterceptor
{
    protected override ResourceResponse OnRequest(ResourceRequest request)
    {
        request.Method = "POST";
        request.AppendUploadBytes("klik_login=1&outkey=323e82945803f3eb68798709237d2ac7&username=asd&password=asd123", 100);
        request.AppendExtraHeader("Content-Type", "application/x-www-form-urlencoded");
        return null;
    }
}

这不工作,任何建议?

推荐答案

下面是一个工作示例(使用.NET4 / 86):

Here is a working sample (using .NET4 / x86) :

public class customInter : IResourceInterceptor
{
    public ResourceResponse OnRequest(ResourceRequest request)
    {
        // Put your code here
        return null;
    }

    public bool OnFilterNavigation(NavigationRequest request)
    {
        return false;
    }
}

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void WebCoreOnStarted(object sender, 
                                  CoreStartEventArgs coreStartEventArgs)
    {
        var interc = new customInter();
        WebCore.ResourceInterceptor = interc;
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        var interc = new customInter();
        WebCore.ResourceInterceptor = interc;

        // Replace "webControl1" and Uri with your information
        this.webControl1.Source = new Uri("http://example-site.com");
    }
}