I am trying to build a very simple app, but it's turning out to be a much more difficult task than one could imagine.
I need to use a simple User Interface , with the basic two text fields, UserName & PassWord (done), and once the login button is depressed, it logs into gmail (or any corporate Gmail account) via an https POST (I think all gmail access is now done through 'https' only) and the simple UI closes, and Safari opens up at the Inbox, (not at the Login window).
Is there no way to pass a socket handle or some cookie data to Safari? Or even write a temp file that can be given as parameter to Safari, to open up..?
I've spent about three solid days trying to build other open-source libraries, that I probably don't even need, only to get a stack of build errors...
(What ever happened to a Makefile?) Apple can keep this damn Xcode...
I am actually not even sure if the correct data is being sent to the server...
Here's basically what I've got... anybody with any ideas...?
NSString *urlString = @"https://www.google.com/LoginAction2?service=mail";
// setting up the request object now NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"];
NSString *contentType = [NSString stringWithFormat:@"application/x-www-form-urlencoded"]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"action=https://www.google.com/LoginAction2?service=mail&"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Email="] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:userName] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"&"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Passwd="] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:passWord] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"&"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"continue=https://mail.google.com/&"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"PersistentCookie=yes&"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"signIn=\"Sign in\"&"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"media="] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body]; NSString *msgLength = [NSString stringWithFormat:@"%d", [body length]]; [request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
[pool release];
URLWithString:@"https://mail.google.com/"]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: returnString]];