我有一个MonoTouch iPhone应用程序通过Azure Access Control Service进行联合登录。登录通过嵌入式UIWebView浏览器完成。登录完成后,我想将cookie转移到我的应用程序中。我可以访问
NSHttpCookieStorage.SharedStorage.Cookies
集合,所以我可以找到cookie。但是为了调用后端服务,我需要有一个
System.Net.Cookie
我可以放入CookieContainer发送给服务。
如何在两者之间进行转换...这是唯一的方法吗?
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.Domain,
Path = cookie.Path,
Port = cookie.PortList[0].ToString(), // is this correct??
Secure = cookie.IsSecure,
HttpOnly = cookie.IsHttpOnly
};
答案 0 :(得分:3)
是的,这就是你可以转换的方式。也许你应该在NSHttpCookie上做一个扩展方法?然后你可以打电话给:
var c = cookie.ToCLRCookie ();