【问题标题】:how to send NTLM request in iOS如何在 iOS 中发送 NTLM 请求
【发布时间】:2012-10-24 23:20:33
【问题描述】:

我使用 json(NSJSONSerialization) 和 NSURL 进行服务器客户端通信。到目前为止它工作正常,但现在 NTLM 安全性已在服务器上实现。

谁能告诉我如何在 iOS 中使用 NTLM 发送请求?

谢谢

【问题讨论】:

标签: iphone ios ios5 nsurlconnection ntlm


【解决方案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 请求。我用过这个。

【讨论】:

  • 谢谢!这真是太棒了!你会不会碰巧知道如何设置 NTLM 域?
【解决方案2】:

如果可以使用NSURLProtectionSpace,则提供NSString *NSURLAuthenticationMethodNTLM;认证方式。

即将上线:

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

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-14
    • 1970-01-01
    相关资源
    最近更新 更多