iOSプログラミングを始めたばかりで、これを理解できていません..ログインしているWebサイトに接続しようとしています..POSTを使用しNSURLConnection
て、ログイン資格情報を送信しています..
資格情報は正しく、connectionDidFinishLoading:
呼び出されますが、サイトに完全にログインしていません..ログインは部分的に完了しています..応答を見たときにこれを特定しました..私の理解によると、「connectionDidFinishLoading」は接続が完了しました..私は間違いなくここに何かが欠けています..私のコードは以下です..アドバイスしてください..
- (IBAction)connect:(id)sender {
// Login to the website
urlRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mywebsite.com/login"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSString *post = @"username=myname&password=mypassword";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPBody:postData];
// Start the connection request
urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
}
ここで、応答をログに記録すると、不完全です.最終的な成功ページの間にあるページに着陸しています..したがって、認証は部分的に完了しています..遅延を含める必要がありますか? 助けてください..
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"Connection success.");
NSURLResponse *responseTest;
NSError *error;
NSData *responseDataTest = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&responseTest error:&error];
NSString *responsestring = [[NSString alloc] initWithData:responseDataTest encoding:NSASCIIStringEncoding];
NSLog(@"Recieved response.. %@",responsestring);
}
前もって感謝します..