通过在窗口电话会话cookie web浏览器导航 [英] WebBrowser navigate via session cookie in window phone

查看:132
本文介绍了通过在窗口电话会话cookie web浏览器导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过的HttpWebRequest 登录按发表方法的网站。在开始的时候,我创建了一个纵向页面,让用户输入用户名和密码,访问网页。我成功地发布的数据,并获得在 HTML 从网站的内容。最后,我使用 Webrowser.NavigateTostring 方法,以显示在我创建了web浏览器的网站。

I am trying to login a website by POST method through HttpWebRequest. In the beginning, i create a portrait page to let user to enter username and password and access the web page. I successfully to Post the data and get the HTML content from the website. Finally I using the Webrowser.NavigateTostring method to display the website in the webBrowser I create.

问题1 :web浏览器里面,我不能做的网站的任何行动。在正常的web浏览器,成功后登录我可以做任何操作,例如访问活动forum..but我面对的是我无法浏览到活动论坛或任何论坛。

Problem 1: Inside the webBrowser, I can not do any action in the website. In the normal webBrowser, after successfully login I can do any action such as go to event forum..but what i face is I can't navigate to event forum or any forum.

问题2 :web浏览器里面,图像不会呈现如用户的图片,产品图片。我也尝试使用 IsolatedStorage 方法来显示在 HTML 的内容,但它也非工作。

Problem 2: Inside the webBrowser, the image will not showing eg, user picture, product picture. I also trying to use IsolatedStorage method to show the HTML content but it also non work.

我是混淆了wheather Webrowser.NavigateTostring 法是一种将异步操作以在互联网上的网站?什么我做错了吗?还是我找错了方向?

What I confusing is wheather the Webrowser.NavigateTostring method is a way to asynchronous operation to the website in internet? and what I doing wrong? or I looking for wrong direction?

任何帮助将是AP preciated。谢谢你。

Any help would be appreciated. Thank you.

推荐答案

此方式将这些问题遭受如果使用加载HTML WebBrowser.NavigateToString 或隔离相对链接的图像存储无,脚本或CSS会工作。此外,它不可能从的HttpWebRequest 任何cookie传递给 web浏览器

This way will suffer from these problems as if you load the HTML using WebBrowser.NavigateToString or from Isolated Storage none of the relative links to images, scripts or CSS will work. Also it is impossible to pass any Cookies from HttpWebRequest to the WebBrowser

要做到这一点的方法是使用的 WebBrowser控件本身做POST。还有就是 WebBrowser.Navigate 方法的如记录在MSDN上这里。这将允许你POST数据到您的网址。

The way to do this is to use the WebBrowser control itself to do the POST. There is a overload of the WebBrowser.Navigate method as documented on MSDN here. That will allow you to POST data to your URL.

// generate your form data based on the data you got from your "portrait page" 
// and get the bytes from that.
// (e.g. write your post data to a MemoryStream as UTF8 and get its bytes)
byte[] formBytes = ...

// write HTTP headers here, including the type of data you're posting, e.g.:
string headers = "Content-Type: application/x-www-form-urlencoded" 
   + Environment.NewLine;


Uri uri = ... // where you want the POST data to be sent

this.webBrowser.Navigate(uri, formBytes, headers);

这样,你的Web浏览器将进行正确的初始化和你的Cookie,图片,脚本和CSS都应该工作。

That way your web browser will be properly initialized and your cookies, images, scripts and CSS should all work.

这篇关于通过在窗口电话会话cookie web浏览器导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆