How do I pass login information to a website from UIWebView directly without any need of logging in once again?

[亡魂溺海] 提交于 2019-12-04 05:23:29
Dinesh

I have discovered way to solve this in a Objective-C way. We can use NSURLConnection to post the form.

Code:

 NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://mobile.twitter.com/session"]
                                                 cachePolicy:NSURLRequestUseProtocolCachePolicy                                              timeoutInterval:60.0];

[theRequest setHTTPMethod:@"POST"];

NSString *postString = [NSString stringWithFormat:@"authenticity_token=%@&username=%@&password=%@",@"9b670208fd22850ec791",@"urUsername",@"urPWD"];
[theRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
    // Create the NSMutableData to hold the received data.
    // receivedData is an instance variable declared elsewhere.
    receivedData = [[NSMutableData data] retain];
} else {
    // Inform the user that the connection failed.
}

Ask me if you need more information.

If you have developed the website yourself, why not create another entry point where you pass the username/password securely, using ssl, to the page? If SSL is not an options, you could generate a token within the app and pass this. No need for username/password to be passed at all then.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!