1
我想通過使用NSURLConnection連接並使用我的用戶名和密碼登錄。我可以提出發帖請求,也可以收到回覆,但我無法保持會話。收到我的請求後,我收到以下消息:無法維護NSURLConnection上的會話
此係統需要使用HTTP cookie來驗證授權信息。 我們的系統檢測到您的瀏覽器已禁用HTTP Cookie,或不支持它們。 有關如何正確配置瀏覽器以便與本系統配合使用的更多信息,請參閱瀏覽器中的「幫助」頁面。
我的代碼,以使連接是在這裏:
NSMutableURLRequest *request = nil;
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://loginsite.com"]];
[[NSHTTPCookieStorage sharedHTTPCookieStorage]setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
NSString *post = [NSString stringWithFormat:@"username=username&pass=password"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setTimeoutInterval: 15];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
_urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[_urlConnection start];
我會很高興,如果有人能幫助我。