2

所以,我在这个线程上看到了这个问题

Awesomnium 帖子参数

基本上我想知道如何实现资源拦截器,因为我找不到它..我也在使用 c#,我通过对象浏览器搜索并没有找到类...

这是我的代码..或多或少与上面的线程相同

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;
    }
}

这不起作用,有什么建议吗?

4

1 回答 1

4

这是一个工作示例(使用 .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");
    }
}
于 2013-10-06T19:59:48.740 回答