<legend id='7sgrY'><style id='7sgrY'><dir id='7sgrY'><q id='7sgrY'></q></dir></style></legend>
      <bdo id='7sgrY'></bdo><ul id='7sgrY'></ul>
    <tfoot id='7sgrY'></tfoot>
  1. <i id='7sgrY'><tr id='7sgrY'><dt id='7sgrY'><q id='7sgrY'><span id='7sgrY'><b id='7sgrY'><form id='7sgrY'><ins id='7sgrY'></ins><ul id='7sgrY'></ul><sub id='7sgrY'></sub></form><legend id='7sgrY'></legend><bdo id='7sgrY'><pre id='7sgrY'><center id='7sgrY'></center></pre></bdo></b><th id='7sgrY'></th></span></q></dt></tr></i><div id='7sgrY'><tfoot id='7sgrY'></tfoot><dl id='7sgrY'><fieldset id='7sgrY'></fieldset></dl></div>

    1. <small id='7sgrY'></small><noframes id='7sgrY'>

    2. 是否可以使用 sharedHTTPCookieStorage 为 UIWebView 手动设置 cookie?

      Is it possible to set a cookie manually using sharedHTTPCookieStorage for a UIWebView?(是否可以使用 sharedHTTPCookieStorage 为 UIWebView 手动设置 cookie?)
      <i id='14jMO'><tr id='14jMO'><dt id='14jMO'><q id='14jMO'><span id='14jMO'><b id='14jMO'><form id='14jMO'><ins id='14jMO'></ins><ul id='14jMO'></ul><sub id='14jMO'></sub></form><legend id='14jMO'></legend><bdo id='14jMO'><pre id='14jMO'><center id='14jMO'></center></pre></bdo></b><th id='14jMO'></th></span></q></dt></tr></i><div id='14jMO'><tfoot id='14jMO'></tfoot><dl id='14jMO'><fieldset id='14jMO'></fieldset></dl></div>
    3. <legend id='14jMO'><style id='14jMO'><dir id='14jMO'><q id='14jMO'></q></dir></style></legend>

          <tbody id='14jMO'></tbody>

        <small id='14jMO'></small><noframes id='14jMO'>

        <tfoot id='14jMO'></tfoot>

          • <bdo id='14jMO'></bdo><ul id='14jMO'></ul>

              • 本文介绍了是否可以使用 sharedHTTPCookieStorage 为 UIWebView 手动设置 cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 iOS 应用程序中有 webviews,需要验证 cookie 才能正确验证.我正在寻找一种在 iOS 应用程序的 web 视图中设置 cookie 的方法,而无需发出出站请求来设置 cookie,因为我已经在客户端上拥有了身份验证信息.

                此帖子向我们展示了 UIWebView cookie 的存储位置.p>

                现在我正在加载一个隐藏的 Web 视图来发出出站请求,但我希望不必发出外部请求来设置简单的 cookie.

                解决方案

                是的,你可以这样做.首先,在 applicationDidBecomeActive 添加这一行

                [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

                cookieAcceptPolicy 是跨应用共享的,并且可以在您不知情的情况下进行更改,因此您需要确保每次应用运行时都拥有所需的接受策略.

                然后,设置cookie:

                NSMutableDictionary *cookieProperties = [NSMutableDictionary 字典];[cookieProperties setObject:@"testCookie" forKey:NSHTTPCookieName];[cookieProperties setObject:@"someValue123456" forKey:NSHTTPCookieValue];[cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieDomain];[cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieOriginURL];[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];//将过期时间设置为从现在起一个月或您选择的任何 NSDate//这使得 cookie 是无会话的,它将在 web 会话和应用程序启动中持续存在///如果您希望在您的应用退出时销毁 cookie,请不要设置此项[cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];

                此 cookie 的名称为 testCookie,值为 someValue123456,将与任何 http 请求一起发送到 www.example.com.

                关于设置 cookie 的一大注意事项,请在此处查看我的问题!

                NSHTTPCookieStorage 状态未在应用退出时保存.有任何权威的知识/文档吗?

                I have webviews inside of an iOS application that require an authentication cookie to be properly authenticated. I'm looking for a way to set a cookie inside of an iOS application's webview without having to make an outbound request to set the cookie as I have auth information on the client already.

                This post shows us where the UIWebView cookies are stored.

                Right now I'm loading a hidden web view to make an outbound request but would prefer not to have to make an external request for setting a simple cookie.

                解决方案

                Yes, you can do this. First, in applicationDidBecomeActive add this line

                [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
                

                The cookieAcceptPolicy is shared across apps and can be changed without your knowledge, so you want to be sure you have the accept policy you need every time your app is running.

                Then, to set the cookie:

                NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
                [cookieProperties setObject:@"testCookie" forKey:NSHTTPCookieName];
                [cookieProperties setObject:@"someValue123456" forKey:NSHTTPCookieValue];
                [cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieDomain];
                [cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieOriginURL];
                [cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
                [cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
                
                // set expiration to one month from now or any NSDate of your choosing
                // this makes the cookie sessionless and it will persist across web sessions and app launches
                /// if you want the cookie to be destroyed when your app exits, don't set this
                [cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];
                
                NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
                [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
                

                This cookie has the name testCookie and value someValue123456 and will be sent with any http request to www.example.com.

                For one big caveat to setting cookies, please see my question here!

                NSHTTPCookieStorage state not saved on app exit. Any definitive knowledge/documentation out there?

                这篇关于是否可以使用 sharedHTTPCookieStorage 为 UIWebView 手动设置 cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                <legend id='DG15X'><style id='DG15X'><dir id='DG15X'><q id='DG15X'></q></dir></style></legend>

                  <tfoot id='DG15X'></tfoot>
                • <i id='DG15X'><tr id='DG15X'><dt id='DG15X'><q id='DG15X'><span id='DG15X'><b id='DG15X'><form id='DG15X'><ins id='DG15X'></ins><ul id='DG15X'></ul><sub id='DG15X'></sub></form><legend id='DG15X'></legend><bdo id='DG15X'><pre id='DG15X'><center id='DG15X'></center></pre></bdo></b><th id='DG15X'></th></span></q></dt></tr></i><div id='DG15X'><tfoot id='DG15X'></tfoot><dl id='DG15X'><fieldset id='DG15X'></fieldset></dl></div>

                    <bdo id='DG15X'></bdo><ul id='DG15X'></ul>
                      <tbody id='DG15X'></tbody>

                    <small id='DG15X'></small><noframes id='DG15X'>