代码之家  ›  专栏  ›  技术社区  ›  Greta

UWP Xamarin C#-WebView返回导航返回页已过期

  •  0
  • Greta  · 技术社区  · 6 年前

    该应用程序显示一个网站与网络视图。

    网页已过期。 信息

    var request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, new Uri("http://example.com/index.php"));
    
    IHttpContent content = new HttpFormUrlEncodedContent(new [] { (new KeyValuePair<string, string>("param", myParam)) });
    request.Content = content;
    webView.NavigateWithHttpRequestMessage(request);
    

    我在Xamarin.Android应用程序上遇到了类似的问题,我决定将以下代码添加到WebView:

    webView.Settings.SetAppCacheEnabled(true);
    webView.Settings.SetAppCacheMaxSize(8 * 1024 * 1024);
    webView.Settings.CacheMode = CacheModes.CacheElseNetwork;
    

    我试图看到一个类似的配置UWP,但我没有找到任何关于它。

    有人能帮我吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Greta    6 年前

                    var myFilter = new HttpBaseProtocolFilter();
                    myFilter.AllowAutoRedirect = true;
                    myFilter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;
                    myFilter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;
                    var cookieManager = myFilter.CookieManager;
    
                    var request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, new Uri("http://example.com/index.php"));
                    IHttpContent content = new HttpFormUrlEncodedContent(new [] { (new KeyValuePair<string, string>("param", myParam)) });
                    request.Content = content;
    
                    using (var client = new Windows.Web.Http.HttpClient())
                    {
                        var result = await client.SendRequestAsync(request);
                        result.EnsureSuccessStatusCode();
                        var resultContent = await result.Content.ReadAsStringAsync();
                    }
    
                    webView.Settings.IsJavaScriptEnabled = true;
                    webView.Settings.IsIndexedDBEnabled = true;
    
                    webView.Navigate(new Uri("http://example.com/index.php"));
    

    链接到-> https://dzone.com/articles/sharing-sessions-between-httpclient-and-webviews-o

    推荐文章