2012-05-21 44 views
0

我30分鐘前做的舊帖子已經看到它的所有回覆被刪除了。首先,我想道歉我的英文給所有主持人,每次我寫東西時都糾正了我在這個論壇:)。在我的WebBrowser中插入餅乾

好吧這麼基本的問題是,我需要添加一個令牌在我的WebBrowser餅乾的銀行應用程序主要完成與webviews。 我寫了一個顯示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。

有人已經看到了嗎?

感謝, 雷諾

編輯:我糾正了conserned線,使其工作!

+0

使用Dispatcher調用NavigateToString –

回答

1

由於您的回調位於不同的線程上,因此您需要使用分派器來修改UI。

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

好吧,我認爲回調是在UIthread上。 thx非常多的傢伙,它現在就像一種魅力! –