gpt4 book ai didi

ios - 使用 "NSHTTPCookie cookieWithProperties"创建 cookie 失败

转载 作者:可可西里 更新时间:2023-11-01 05:04:47 25 4
gpt4 key购买 nike

我使用下面的代码来创建一个cookie,但是失败了。(iOS SDK 5)

// add cookie
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
req.URL, NSHTTPCookieOriginURL,
@"MLSTORAGE", NSHTTPCookieName,
@"1234567890", NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
NSLog(@"\nurl: %@\ncookie: %@", req.URL, cookie);
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
//

日志是:

2012-07-26 18:30:49.914 Motilink[15289:707] -[FMWebDAVRequest sendRequest:][Line 154] 
url: http://210.116.114.195:8080/MLServer/storage/
cookie: (null)

有人知道如何创建 cookie 吗?

最佳答案

在您的请求 URL 中使用 NSHTTPCookieOriginURL 时似乎出现了问题。

尝试使用这段代码,它对我有用:

// add cookie
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
req.URL.host, NSHTTPCookieDomain,
req.URL.path, NSHTTPCookiePath,
@"MLSTORAGE", NSHTTPCookieName,
@"1234567890", NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
NSLog(@"\nurl: %@\ncookie: %@", req.URL, cookie);
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
//

但是,我不知道为什么 NSHTTPCookieOriginURL 在这里不起作用。

希望对您有所帮助,

关于ios - 使用 "NSHTTPCookie cookieWithProperties"创建 cookie 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11667468/

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