2013年11月16日 星期六

API with logined in objective-c(iOS)

 

The UIWebView will handle session & cookie.

UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:webView];
 
NSString* username = @"";
NSString* password = @"";
 
NSURL* url = [NSURL URLWithString:@"https://ic.ridgefield.org/campus/verify.jsp"];
 
NSString* body = [NSString stringWithFormat:@"appName=ridgefield&username=%@&password=%@", username, password];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
request.HTTPMethod = @"POST";
request.HTTPBody = [body dataUsingEncoding:NSStringEncodingConversionAllowLossy];
 
[webView loadRequest:request];

 

接著只要利用 UIWebView 的物件呼叫 API,那麼就是以登入的身分執行API。

沒有留言:

張貼留言