繁体   English   中英

使用ios应用程序中的活动目录用户对Web服务进行身份验证?

[英]Authenticate a webservice with active directory users in ios application?

我在ios中开发客户端应用程序。 在此应用程序中,我需要从Web服务获取服务数据,该服务仅对活动目录用户可访问,而对匿名用户则不可访问。我如何使用活动目录用户凭据从该Web服务访问和获取数据。

提前致谢

在这种情况下,您必须在访问Web服务时传递用户凭据。

  NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"Ur URL"]];
        NSString *userPasswordString = [NSString stringWithFormat:@"%@:%@",username,password];
        NSData * userPasswordData = [userPasswordString dataUsingEncoding:NSUTF8StringEncoding];
        NSString *base64EncodedCredential = [userPasswordData base64EncodedStringWithOptions:0];
        NSString *authString = [NSString stringWithFormat:@"Basic %@", base64EncodedCredential];

        NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
        NSString *msgLength =[NSString stringWithFormat:@"%lu", (unsigned long)[poststr length]];

        [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [req addValue:[NSString stringWithFormat:@"http://www.hello.com"] forHTTPHeaderField:@"SOAPAction"];
        [req addValue:authString forHTTPHeaderField:@"Authorization"];
        [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
        [req setHTTPMethod:@"POST"];
        [req setHTTPBody: [poststr dataUsingEncoding:NSUTF8StringEncoding]];

 [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
         {
            // NSError *error1;


         }];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM