在我的Web浏览器中插入cookie

时间:2012-05-21 15:40:43

标签: windows-phone-7

我已经做了30分钟的旧帖子已经看到所有的回复被删除了..首先,我想向所有主持人道歉,我每次在这个论坛上写东西时都纠正了我:) 。

好的基本问题是我需要在我的WebBrowser Cookies中添加一个令牌,用于主要使用webview完成的银行应用程序。 我写了一个显示cookie的测试网页。我试着像这样打它:

private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {

            string testCookies = "http://devlbpaccescomptewp7.clicmobile.com/test-read-cookie.html?timeStamp=";
            testCookies += DateTime.Now.Millisecond;
            Cookie cookie = new Cookie("cookie", "lol");
            Uri test = new Uri(testCookies, UriKind.Absolute);
            CookieContainer cc = new CookieContainer();
            cc.Add(test,cookie);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(testCookies);
            req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)";
            req.Method = "POST";
            req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            req.CookieContainer = cc;

            //HttpWebResponse myWebResponse = (HttpWebResponse)req.get
            req.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), req); 

            uriList = new List<Uri>();

           // wB.Navigate(test);
           // wB.Navigate(new Uri(home, UriKind.Absolute));
           wB.Navigating += new EventHandler<NavigatingEventArgs>(wB_Navigating);
        }

        private void ReadWebRequestCallback(IAsyncResult callbackResult)
        {
            HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);

            using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
            {
                string results = httpwebStreamReader.ReadToEnd();
                Deployment.Current.Dispatcher.BeginInvoke(() => wB.NavigateToString(results));


            }
            myResponse.Close();
        }

我在wb.NavigateToString行上获得了UnauthorizedAccessExeption。

有人已经看过了吗?

谢谢, 雷诺

编辑:我更正了保留的行以使其正常工作!

1 个答案:

答案 0 :(得分:1)

由于您的回调位于不同的线程上,因此您需要使用Dispatcher来修改UI。

Deployment.Current.Dispatcher.BeginInvoke(() => wb.NavigateToString(results));