how to send NTLM request in iOS

天大地大妈咪最大 提交于 2019-12-11 13:39:30

问题


I was using json(NSJSONSerialization) and NSURL for server client communication. Till now it was working fine but now NTLM security has been implemented on server.

Can anyone tell me how to send request with NTLM in iOS ?

Thanks


回答1:


If you can use NSURLProtectionSpace, it provides NSString *NSURLAuthenticationMethodNTLM; authentication method.

Something on the lines:

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



回答2:


This code will be helpful

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");
    }

See the Tutorial and sample code

for NTLM request for iOS. I used this.



来源:https://stackoverflow.com/questions/13226750/how-to-send-ntlm-request-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!