0

I am creating an iOS app using Xamarin.

I am loading a url on a web view. This url is hosted on a secure server which needs to be authenticated.

I store cookies from login service of the app and want to set these cookies when loading the web view. But I cannot get any method to add it.

Could any one help regarding this?

Loading url is done by this line webview.LoadRequest(new NSUrlRequest(urlq)); But I can't add the cookies.

angak
  • 406
  • 2
  • 12
Ajay shanker
  • 65
  • 1
  • 8
  • Could you show the code where you load and store the cookie? – angak Mar 30 '15 at 08:38
  • possible duplicate of [Set Cookie for UIWebView requests](http://stackoverflow.com/questions/9396718/set-cookie-for-uiwebview-requests) – IdoT Mar 30 '15 at 08:53
  • @angak As i try set cookies in HttpWebRequest ? Because i didn't get any method to set cookies in loading url. – Ajay shanker Mar 30 '15 at 09:32

1 Answers1

0

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; 

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