gpt4 book ai didi

iOS:如何为 NSHTTPCookie 设置 httponly 标志

转载 作者:行者123 更新时间:2023-12-04 21:19:29 29 4
gpt4 key购买 nike

我正在使用以下代码来构造 NSHTTPCookie 但是没有选项可以为 cookie 设置 httpOnly 标志

[cookieProperties setObject:@"name" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"value" forKey:NSHTTPCookieValue];
[cookieProperties setObject:[NSNumber numberWithBool: NO] forKey:NSHTTPCookieDiscard];
[cookieProperties setObject:[dictionary objectForKey:@"isSecure"] forKey:NSHTTPCookieSecure];


[cookieProperties setObject:@"abc.xyz.com" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"abc.xyz.com" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];

最佳答案

有一个 undocumented cookie property key (通过 @mikewest 找到):

// Undocumented property of NSHTTPCookie.
NSString* const kNSHTTPCookieHttpOnly = @"HttpOnly";



我在 Swift 中尝试过,它的代码完成了预期的工作。
import Foundation

extension HTTPCookiePropertyKey {
static let httpOnly = HTTPCookiePropertyKey("HttpOnly")
}

let cookie = HTTPCookie(properties: [
.domain: "example.org",
.path: "/",
.name: "Cookie Example",
.value: "Om nom nom",

.version: 1, // RFC2965 for HttpOnly cookies
.httpOnly: true
])!

print(cookie.isHTTPOnly) // true

关于iOS:如何为 NSHTTPCookie 设置 httponly 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27719699/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com