How do I convert an NSHttpCookie to a System.Net.Cookie in MonoTouch?
I have a MonoTouch iPhone app that does federated sign in via the Azure Access Control Service. The login is done via an embedded UIWebView browser. When the login is done, I want to transfer the cookie into my app. I have access to the
NSHttpCookieStorage.SharedStorage.Cookies
collection, so I can find the cookie. But in order to call the back end services, I need to have a
System.Net.Cookie
that I can put into a CookieContainer to send to the service.
How do I convert between the two... is this the only way?
NSHttpCookie cookie = NSHttpCookieStorage.SharedStorage.Cookies[0];
System.Net.Cookie newCookie = new System.Net.Cookie()
{
Name = cookie.Name,
Value = cookie.Value,
Version = (int) cookie.Version,
Expires = cookie.ExpiresDate,
Domain = cookie.Domai开发者_StackOverflow社区n,
Path = cookie.Path,
Port = cookie.PortList[0].ToString(), // is this correct??
Secure = cookie.IsSecure,
HttpOnly = cookie.IsHttpOnly
};
Yes, that is how you could convert. Perhaps you should just make an extension method on NSHttpCookie? Then you could call something like:
var c = cookie.ToCLRCookie ();
精彩评论