Set Cookie for UIWebView requests

前端 未结 5 1793
抹茶落季
抹茶落季 2021-01-05 18:54

I want to embed an UIWebView into my MonoTouch application for an area that is not yet implemented natively.

In order to authenticate with the website I

5条回答
  •  心在旅途
    2021-01-05 19:44

    This might give you a lead. Previously I used a similar strategy to make a

    WebRequest to a site and collect cookies which were stored in the .Net/Mono CookieStore. Then when loading a url in the UIWebView I copied those cookies over to the NSHttpCookieStorage.

    public NSHttpCookieStorage _cookieStorage; 
    
        /// 
        /// Convert the .NET cookie storage to the iOS NSHttpCookieStorage with Login Cookies
        /// 
        void DotNetCookieStoreToNSHttpCookieStore()
        {
            foreach (Cookie c in _cookies.GetCookies(new Uri(UrlCollection["Login"], UriKind.Absolute))) {
                Console.WriteLine (c);
                _cookieStorage.SetCookie(new NSHttpCookie(c));
            }
        }
    

提交回复
热议问题