简体   繁体   English

如何在WinRT WebView中使会话保持活动状态

[英]How to keep session alive in WinRT WebView

I am using the following code share the cookie between HttpClient and WebView in WinRT 我正在使用以下代码在WinRT中在HttpClient和WebView之间共享cookie

var pageUri = new Uri(TargetPage);

var filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
var cookie = new Windows.Web.Http.HttpCookie("key", pageUri.Host,    pageUri.LocalPath);
cookie.Value = "value";
filter.CookieManager.SetCookie(cookie, false);

  var request = new  Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, loginUri);
  webView.NavigateWithHttpRequestMessage(request);

I am using this code to bypass login request in Web browser. 我正在使用此代码绕过Web浏览器中的登录请求 But here the issue is after 5 minutes the cookie get expires and It again ask for credential for proceeding further. 但是这里的问题是5分钟后,cookie的获取过期了 ,它再次要求提供凭证以继续进行操作。 So my doubt is, 所以我的疑问是

Is there any tweak available to make this browser alive with the cookie / Session . 有没有可用的调整使该浏览器与cookie / Session保持一致 May be like injecting some Java Script code to browser or something similar to this. 可能就像注入一些Java Script代码到浏览器或类似的东西。

I am currently sending WebRequest to authenticate again using DispatureTimer with interval of 5 minutes and refreshes the cookie again and again. 我当前正在发送WebRequest以使用DispatureTimer间隔5分钟再次进行身份验证,并一次又一次刷新cookie。 I don't feel it as a good workaround to this issue. 我认为这不是解决此问题的好方法。 Because it consumes un-wanted data and battery usage. 因为它消耗了不需要的数据和电池电量。

So anyone please help me to find a workaround to solve this issue. 因此,任何人都可以帮助我找到解决此问题的解决方法。

You're already doing the right thing with the DispatchTimer. 您已经使用DispatchTimer做正确的事情。 I don't know why you feel that it's incorrect, especially since you're already kind of hacking the website by hosting it in a webview. 我不知道您为什么会认为它是不正确的,特别是因为您已经通过将其托管在Webview中来入侵网站了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM