Windows Phone中的Web浏览器查询

时间:2014-05-03 01:00:49

标签: c# wpf silverlight windows-phone-7 windows-phone-8

我已经获得了以下代码,但是当我构建它时,我在WebBrowserDocumentCompletedEventArgs上收到错误,告诉我无法找到类型或命名空间。

我一直在网上搜索并尝试添加DLL超过一个小时。有人可以帮忙吗?

private void b_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser b = sender as WebBrowser;
        string response = b.DocumentText;

        // looks in the page source to find the authenticity token.
        // could also use regular exp<b></b>ressions here.
        int index = response.IndexOf("authenticity_token");
        int startIndex = index + 41;
        string authenticityToken = response.Substring(startIndex, 40);

        // unregisters the first event handler
        // adds a second event handler
        b.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted);
        b.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(b_DocumentCompleted2);

        // format our data that we are going to post to the server
        // this will include our post parameters.  They do not need to be in a specific
        //  order, as long as they are concatenated together using an ampersand ( & )
        string postData = string.Format("authenticity_token={2}&session[username_or_email]={0}&session[password]={1}&commit={3}", username, password, authenticityToken, commit);

        ASCIIEncoding enc = new ASCIIEncoding();

        //  we are encoding the postData to a byte array
        b.Navigate("https://twitter.com/sessions", "", enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");
    }

0 个答案:

没有答案