如何在 MonoTouch 中将 NSHttpCookie 转换为 System.Net.Cookie? [英] How do I convert an NSHttpCookie to a System.Net.Cookie in MonoTouch?
问题描述
我有一个 MonoTouch iPhone 应用程序,它通过 Azure 访问控制服务进行联合登录.登录是通过嵌入式 UIWebView 浏览器完成的.登录完成后,我想将 cookie 传输到我的应用程序中.我可以访问
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
收集,所以我可以找到cookie.但是为了调用后端服务,我需要有一个
collection, so I can find the cookie. But in order to call the back end services, I need to have a
System.Net.Cookie
我可以放入 CookieContainer 以发送到服务.
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.Domain,
Path = cookie.Path,
Port = cookie.PortList[0].ToString(), // is this correct??
Secure = cookie.IsSecure,
HttpOnly = cookie.IsHttpOnly
};
推荐答案
是的,这就是您可以转换的方式.也许你应该在 NSHttpCookie 上做一个扩展方法?然后你可以调用类似的东西:
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 ();
这篇关于如何在 MonoTouch 中将 NSHttpCookie 转换为 System.Net.Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!