问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/5505707/how-do-i-pass-login-information-to-a-website-from-uiwebview-directly-without-any