Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to open some website in my iphone app using UIWebView. The website requires username and password and I have these username and password.

I was wondering is there anyway I can open the website in my UIWebView without any login screen? I mean as I already have the username and password, can I use this information to log in to website automatically and show the required necessary page onto my UIWebView iphone app.

I just want to get rid of logging to website as users have already entered the login information when they open the app. Thats redundant.

Any help is greatly appreciated.

Thanks.

like image 573
Dinesh Avatar asked Mar 31 '11 20:03

Dinesh


1 Answers

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.

like image 154
Dinesh Avatar answered Oct 16 '22 03:10

Dinesh