logowanie po https
#1
Napisano 20 września 2009 - 19:22
#2
Napisano 21 września 2009 - 15:06
Secure Web Connection - iPhone Dev SDK Forum
W sumie na podanym forum jest kilka watkow dotyczacych laczenia sie z serwerem poprzez http i https. Wystarczy uzyc opcji search.
#3
Napisano 26 września 2009 - 10:33
thx za info
przeszukalem forum i nic nie moge wykombinowac
to jest fragment kodu:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"Webmail" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
[window makeKeyAndVisible];
}
w pliku "html" jest przekierowanie po podaniu loginu i pass na strone "HTTPS"
#4
Napisano 26 września 2009 - 12:41
#5
Napisano 26 września 2009 - 13:31
@interface WebMailAppDelegate : NSObject <UIApplicationDelegate> { NSManagedObjectModel *managedObjectModel; NSManagedObjectContext *managedObjectContext; NSPersistentStoreCoordinator *persistentStoreCoordinator; UIWindow *window; IBOutlet UIWebView *webView; } @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; @property (nonatomic, retain) IBOutlet UIWindow *window; - (NSString *)applicationDocumentsDirectory; @end*.m
#import "WebMailAppDelegate.h" @implementation WebMailAppDelegate @synthesize window; #pragma mark - #pragma mark Application lifecycle - (void)applicationDidFinishLaunching:(UIApplication *)application { NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"Webmail" ofType:@"html"]; NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile]; [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]]; [window makeKeyAndVisible]; } - (void)applicationWillTerminate:(UIApplication *)application { NSError *error = nil; if (managedObjectContext != nil) { if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } } #pragma mark - #pragma mark Core Data stack - (NSManagedObjectContext *) managedObjectContext { if (managedObjectContext != nil) { return managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { managedObjectContext = [[NSManagedObjectContext alloc] init]; [managedObjectContext setPersistentStoreCoordinator: coordinator]; } return managedObjectContext; } - (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel != nil) { return managedObjectModel; } managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; return managedObjectModel; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"AETERNUS_WebMail.sqlite"]]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return persistentStoreCoordinator; } #pragma mark - #pragma mark Application's Documents directory - (NSString *)applicationDocumentsDirectory { return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; } #pragma mark - #pragma mark Memory management - (void)dealloc { [managedObjectContext release]; [managedObjectModel release]; [persistentStoreCoordinator release]; [window release]; [super dealloc]; } @endplik webmail.html
<html> <body> <form action="https://adres.com/default/dologin.php" method="post"> <center> <input name="username"> <input name="password" type="password"> <input type="submit" value="log in"> <input name="mode" type="hidden" value="mini"> </center> </form> </body> </html>
#6
Napisano 26 września 2009 - 14:45
//edit
Dobra, chyba wiem o co chodzi. Zmodyfikowalem jedna metode:
@interface NSURLRequest (DummyInterface) + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host; + (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host; @end @implementation WebMailAppDelegate ... - (void)applicationDidFinishLaunching:(UIApplication *)application { NSURL *myWebserverURL = [NSURL URLWithString:@"https://adres.com/default/dologin.php"]; [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]]; NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"Webmail" ofType:@"html"]; NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile]; [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]]; [window makeKeyAndVisible]; //CGRect webFrame = CGRectMake(0, 0, 320, 480); //UIWebView*myWebView = [[UIWebView alloc] initWithFrame:webFrame]; //myWebView.backgroundColor = [UIColor whiteColor]; //[window addSubview:myWebView]; //[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://adres.com/default/dologin.php"]]]; }
Teraz wyjasnienie. Musisz zaakceptowc certyfikat przy pomocy [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]];
Tylko ze nie wiem, czy przypadkiem nie musisz sciagnac certyfikatu ze swojej strony, zeby zadzialalo.
Dlatego tez, jakby nie wyszlo, to odkomentuj kawalek kodu ktory dopisalem, sciagnij ten certyfikat, a nastepnie zakomentuj i odpal ponownie. U mnie dziala =
Użytkownicy przeglądający ten temat: 1
0 użytkowników, 1 gości, 0 anonimowych