如何在MonoTouch中将NSHttpCookie转换为System.Net.Cookie? [英] How do I convert an NSHttpCookie to a System.Net.Cookie in MonoTouch?

查看:93
本文介绍了如何在MonoTouch中将NSHttpCookie转换为System.Net.Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆