public static CookieCollection GetCookieCollection()
        {
            var cookieHeader = CookieManager.Instance.GetCookie(digiview.Helper.SettingsHelper.GetPath());

            Android.Webkit.CookieManager cookieManager = Android.Webkit.CookieManager.Instance;
            cookieManager.SetAcceptCookie(true);
            string[] temp = cookieManager.GetCookie(digiview.Helper.SettingsHelper.GetPath()).Split(';');

            CookieCollection cookies = new CookieCollection();

            for (int i = 0; i < temp.Length; i++)
            {
                temp[i] = temp[i].Trim();
                string[] val = temp[i].Split('=');
                Cookie   c   = new Cookie();
                c.Name  = val[0];
                c.Value = val[1];
                for (int j = 2; j < val.Length; j++)
                {
                    c.Value += "=" + val[j];
                }
                c.Path = "/";
                cookies.Add(c);
            }

            return(cookies);
        }
예제 #2
0
            public override void OnPageFinished(WebView view, string url)
            {
                if (Build.VERSION.SdkInt < Build.VERSION_CODES.Lollipop)
                {
                    CookieSyncManager.CreateInstance(context);
                }
                Android.Webkit.CookieManager cookieManager = CookieManager.Instance;
                string cookieStr = cookieManager.GetCookie("https://www.cnblogs.com/");

                if (string.IsNullOrWhiteSpace(cookieStr))
                {
                    return;
                }
                string[] cookieArray = cookieStr.Split(';');
                List <RestSharp.HttpCookie> cookieList = new List <RestSharp.HttpCookie>();

                foreach (var item in cookieArray)
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        string cookieItemText       = item.Trim();
                        RestSharp.HttpCookie cookie = new RestSharp.HttpCookie();
                        int nameIndex = cookieItemText.IndexOf('=');
                        cookie.Name  = cookieItemText.Substring(0, nameIndex);
                        cookie.Value = cookieItemText.Substring(nameIndex + 1, cookieItemText.Length - nameIndex - 1);
                        cookieList.Add(cookie);
                    }
                }
                CookieSyncManager.Instance.Sync();
                List <HttpHeader> headers = new List <HttpHeader>();

                headers.Add(new HttpHeader()
                {
                    Name = "Host", Value = "www.cnblogs.com"
                });
                headers.Add(new HttpHeader()
                {
                    Name = "Origin", Value = "https://www.cnblogs.com"
                });
                headers.Add(new HttpHeader()
                {
                    Name = "X-Requested-With", Value = "XMLHttpRequest"
                });
                headers.Add(new HttpHeader()
                {
                    Name = "Referer", Value = "https://www.cnblogs.com/"
                });
                HttpClientUtil.PostWebHttp <WebResponseMessage, DiggBuryModel>("https://www.cnblogs.com/mvc/vote/VoteBlogPost.aspx", new DiggBuryModel("ansang", 9371764), headers, cookieList,
                                                                               (model) => {
                    System.Diagnostics.Debug.Write(model.Message);
                },
                                                                               (error) =>
                {
                    System.Diagnostics.Debug.Write(error);
                });
                base.OnPageFinished(view, url);
            }
예제 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            _webView = FindViewById <WebView>(Resource.Id.webbrowser_view_webview);
            WebSettings settings = _webView.Settings;

            settings.JavaScriptEnabled = true;
            settings.SetAppCacheEnabled(true);
            settings.BuiltInZoomControls = true;
            settings.SetPluginState(WebSettings.PluginState.On);

            _webView.SetWebChromeClient(new WebChromeClient());

            CookieSyncManager.CreateInstance(this);
            CookieManager cookieManager = CookieManager.Instance;

            cookieManager.RemoveSessionCookie();
            String cookieString = "param=value";

            cookieManager.SetCookie("https://thebridge.spaces.nexudus.com/", cookieString);
            CookieSyncManager.Instance.Sync();

            var abc = new Dictionary <String, String> {
                ["Cookie"] = cookieString
            };

            _webView.LoadUrl(ViewModel.Url, abc);

            try
            {
                if (!string.IsNullOrEmpty(ViewModel.Url))
                {
                    _webView?.SetWebViewClient(new WebViewClient());
                    _webView?.LoadUrl(ViewModel.Url);
                }
            }
            catch (Exception ex)
            {
                Mvx.Resolve <IExceptionService>().HandleException(ex);
            }

            _urlChangedListener = new MvxPropertyChangedListener(ViewModel).Listen(() => ViewModel.Url, () =>
            {
                RunOnUiThread(() =>
                {
                    _webView.StopLoading();
                    _webView.LoadUrl(ViewModel.Url);
                });
            });
        }