Objective c 使用目标C中的安全https Web服务
我必须在Objective C中编辑一段代码,用登录名、密码和cookie容器调用一个安全的https Web服务 代码实际上是:Objective c 使用目标C中的安全https Web服务,objective-c,web-services,cocoa,cookies,cookiecontainer,Objective C,Web Services,Cocoa,Cookies,Cookiecontainer,我必须在Objective C中编辑一段代码,用登录名、密码和cookie容器调用一个安全的https Web服务 代码实际上是: NSString *plistInfosServeurPath = [[NSBundle mainBundle] pathForResource:@"InfosServeur" ofType:@"plist"]; NSDictionary *infosServeurDictionary = [NSDictionary dictionaryWithContentsOf
NSString *plistInfosServeurPath = [[NSBundle mainBundle] pathForResource:@"InfosServeur" ofType:@"plist"];
NSDictionary *infosServeurDictionary = [NSDictionary dictionaryWithContentsOfFile:plistInfosServeurPath];
NSString *urlServeur = [infosServeurDictionary objectForKey:@"serveur_url"];
/* ADDED BY ME */
/* ------- */
NSURLCredential *newcredential = [NSURLCredential credentialWithUser:@"plop" password:@"Plop" persistence:NSURLCredentialPersistenceNone];
NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:@"https://plop.com"
port:443
protocol:@"https"
realm:nil
authenticationMethod:NSURLAuthenticationMethodHTTPBasic];
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:newcredential
forProtectionSpace:space];
/* ------- */
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@/plop.svc/plop/%@", urlServeur, _gare.code]]];
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *result, NSError *error){
if (result)
{
NSArray *trains = [[CJSONDeserializer deserializer] deserializeAsArray:result error:&error];
}
if (erro) {
NSLog(@"connexion NOK");
NSLog(@"ERROR : %@", error);
}
}
];
该代码适用于http中的Web服务,但现在使用https,我尝试添加凭据,但没有成功,并且找不到如何添加cookie容器