【发布时间】:2014-08-24 07:53:06
【问题描述】:
我正在使用 NTLM 服务器身份验证 (SharePoint),我设法使用 NSURLConnection 和凭据发出 GET 请求。
我想要的是从该请求中获取会话 cookie,例如在桌面上,并将它们放入 [NSHTTPCookieStorage sharedHTTPCookieStorage],以便将来在 WebView 中连接。
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSLog(@"Response: %@", [HTTPResponse allHeaderFields]); // Log below
NSArray *cookies = [NSHTTPCookie
cookiesWithResponseHeaderFields:[HTTPResponse allHeaderFields]
forURL:[NSURL URLWithString:@"https://domain.com"]];
NSLog(@"How many Cookies: %d", cookies.count); // GOT 0 HERE
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:[NSURL URLWithString:@"https://domain.com"] mainDocumentURL:nil];
}
我的响应不是我认为的 cookie(我更改了值):
Response: {
"Cache-Control" = "private,max-age=0";
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 1536;
"Content-Type" = "text/html";
Date = "Thu, 03 Jul 2014 09:00:35 GMT";
Etag = "\"{F1F0AAgregr-41DA-AgergA26-51A51B019910},3\"";
Expires = "Wed, 18 Jun 2014 09:00:36 GMT";
"Last-Modified" = "Fri, 02 May 2014 13:35:13 GMT";
MicrosoftSharePointTeamServices = "14.0.0.6120";
"Persistent-Auth" = true;
"Public-Extension" = "http://schemas.microsoft.com/repl-2";
ResourceTag = "rt:F1F0AAE2gerge1B019gerg000003";
SPRequestGuid = "975dccbgregergrgbbeff4f5b5";
Server = "Microsoft-IIS/7.5";
Vary = "Accept-Encoding";
"X-MS-InvokeApp" = "1; RequireReadOnly";
"X-Powered-By" = "ASP.NET";
"X-SharePointHealthScore" = 0;
}
我知道 cookie 的 Expires/Max-Age 值是 Session。 你知道我想做的事情是否可行吗?
谢谢!
【问题讨论】:
标签: ios objective-c sharepoint cookies nsurlconnection