0

是否可以订阅 Windows Phone 应用程序中的所有 Web 请求?我的意思是注册一个全局钩子,每次我向网络服务器发出请求时都会触发它。非常感谢

4

1 回答 1

1

简单的例子:

// Since the property is static, it will be shared by all instances of WebClientWrapper
// Set this before creating an instance of WebClientWrapper
WebClientWrapper.Hook = address => Debug.WriteLine(address);

var webClientWrapper = new WebClientWrapper();
webClientWrapper.DownloadString("http://www.something.com");



public class WebClientWrapper
{
    private readonly WebClient _webClient;

    // This can be string, your custom class of whatever you need
    public static Action<string> Hook { get; set; }

    public WebClientWrapper()
    {
        _webClient = new WebClient();
    }

    public string DownloadString(string address)
    {
        Hook(address);
        return _webClient.DownloadString(address);
    }
}
于 2012-11-13T22:44:24.210 回答