2014-09-18 1 views
0

사용자가 웹 사이트에서 온라인 계정에 로그인 할 수있는 앱을 만드는 방법을 이해하는 데 어려움을 겪고 있습니다. 내 예제는 여기에 로그인 할 것입니다 : https://account.tfl.gov.uk/oyster/앱 내 온라인 계정 로그인

이제 AFNetworking, HTTP POST 요청 등에 대해 많이 읽었습니다.

내가 완전히 잃어 버렸기 때문에이 로그인 방법에 대한 조언은 훌륭 할 것입니다.

+0

JSON. 당신은 REST 스펙을 찾아야 만한다. (존재한다면) 서버 - 클라이언트 통신에 대한 모든 필수 정보를 얻을 수 있어야한다. 일단 그것을 얻으면 POST (NSDictionary의 params) 또는 GET (params가 질의로 이동) 요청을 서버로 보낼 수 있습니다. 희망을 조금 분명히. – Neru

답변

0

를 사용하여 다음과 같은 방법 : 사실 당신이 사이트 있지만, 예를 들어, 사용하여 REST (SOAP) 서비스를 사용 '을 통해'로그인하지

NSString *post = [NSString stringWithFormat:@"Username=%@&Password=%@",@"username",@"password"]; //may be change as per your requirement 

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]]; 

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.yourDoamin.com/test/xyz.aspx"]]]; 

[request setHTTPMethod:@"POST"]; 

[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

[request setHTTPBody:postData]; 

NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self]; 

if(connection) { 
    NSLog(@"Connected"); 
} else { 
    NSLog(@"Connection Error"); 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data 
{ 
    // here check response data in your case login password true or false 
} 


- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    // handle connection error 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
}