2012-11-05 49 views
1

我正在使用json(NSJSONSerialization)和NSURL进行服务器客户端通信。直到现在它工作正常,但现在NTLM安全已在服务器上实现。如何在iOS发送NTLM请求

任何人都可以告诉我如何发送请求与iOS中的NTLM?

感谢

+0

有一个看看这篇文章:http://stackoverflow.com/questions/628935/how-to-perform-an-ntlm-challenge-on-the- iphone?rq = 1和这一个:http://stackoverflow.com/questions/3818120/how-to-implement-ntlm-authentication-for-uiwebview?rq=1 – mttrb

回答

1

这个代码将有助于

NSMutableString *nodeContent = [[NSMutableString alloc]init]; 

    NSString *soapFormat = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
          "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 
          "<soap:Body>\n" 
          "<GetListCollection xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" />\n" 
          "</soap:Body>\n" 
          "</soap:Envelope>\n"]; 



    NSLog(@"The request format is %@",soapFormat); 

    NSURL *locationOfWebService = [NSURL URLWithString:@"http://localhost/_vti_bin/lists.asmx"]; 

    NSLog(@"web url = %@",locationOfWebService); 

    NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService]; 

    NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]]; 


    [theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue:@"http://schemas.microsoft.com/sharepoint/soap/GetListCollection" forHTTPHeaderField:@"SOAPAction"]; 
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    //the below encoding is used to send data over the net 
    [theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]]; 


    NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; 

    if (connect) { 
     webData = [[NSMutableData alloc]init]; 
    } 
    else { 
     NSLog(@"No Connection established"); 
    } 

Tutorial and sample code

iOS版NTLM请求。我用这个。

+1

谢谢!这真是太棒了!你会碰巧知道如何设置NTLM域名? –

1

如果您可以使用NSURLProtectionSpace,它提供了NSString *NSURLAuthenticationMethodNTLM;验证方法。

东西就行:

NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] 
    initWithHost: _host 
    port: 80 
    protocol: @"http" 
    realm: _host 
    authenticationMethod:NSURLAuthenticationMethodNTLM];