我使用JSON(NSJSONSerialization)和NSURL服务器客户端通信。 到目前为止它工作正常,但现在NTLM安全性已在服务器上执行。
谁能告诉我如何使用NTLM发送请求的iOS?
谢谢
我使用JSON(NSJSONSerialization)和NSURL服务器客户端通信。 到目前为止它工作正常,但现在NTLM安全性已在服务器上执行。
谁能告诉我如何使用NTLM发送请求的iOS?
谢谢
如果你可以使用NSURLProtectionSpace ,它提供的NSString * NSURLAuthenticationMethodNTLM; 身份验证方法。
东西就行:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: _host
port: 80
protocol: @"http"
realm: _host
authenticationMethod:NSURLAuthenticationMethodNTLM];
此代码将是有益的
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");
}
查看教程和示例代码
用于为iOS NTLM请求。 我用这个。