为NSURLRequest创建一个cookie? [英] Create a cookie for NSURLRequest?
问题描述
我在NSMutableURLRequest中尝试通过cookie发送验证字符串。我试图通过
I'm trying to send an authentication string via cookie in a NSMutableURLRequest. I'm trying to create the NSHTTPCookie through
+(id)cookieWithProperties:(NSDictionary *)properties
但我无法找到如何指定除了用于身份验证的简单键值对之外的属性。当我只使用我的键值对,返回nil。
But nowhere have I been able to find how to specify the properties other than the simple key-value pair I have for authentication. When I only use my key-value pair, nil is returned.
任何例子,文档或想法将非常感谢。
Any examples, documentation, or thoughts on this would be greatly appreciated.
推荐答案
这是在Cookie中设置属性的方法:
This is how you set properties in a cookie:
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
url, NSHTTPCookieOriginURL,
@"testCookies", NSHTTPCookieName,
@"1", NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
在上面的示例中:
url
, testCookies
和 1
是值。同样, NSHTTPCookieOriginURL
, NSHTTPCookieName
, NSHTTPCookieValue
> 对于 NSDictionary
对象
In the example above:
url
, testCookies
, and 1
are the values. Likewise, NSHTTPCookieOriginURL
, NSHTTPCookieName
, NSHTTPCookieValue
are the keys for the NSDictionary
object, as in key-value pairs.
您使用 NSDictionary
设置/获取属性,并添加到 NSHTTPCookie
。
You set/get properties using NSDictionary
and add to NSHTTPCookie
.
这篇关于为NSURLRequest创建一个cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!