2012-12-18 38 views
3

我正在开发iOS iPad应用程序以连接到Sharepoint。我正在用ASIHTTPRequest框架来做这件事。我的代码看起来像这样:iOS Sharepoint App登录错误

NSURL *url = [NSURL URLWithString:@"https://SHAREPOINTURL"]; 

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

asiRequest = [ASIHTTPRequest requestWithURL:url]; 

[asiRequest setUsername:@"USERNAME"]; 
[asiRequest setPassword:@"PASSWORD"]; 

[asiRequest setDelegate:self]; 
[asiRequest appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
[asiRequest addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"]; 
[asiRequest startAsynchronous]; 

到目前为止,这么好,但是当我调试这个,我得到一个403 FORBIDDEN错误。为什么? 在我看来,我不认为这些错误是用户名和密码。请求可能有问题吗?

回答

0

既然你没有发布你的网址,我不得不问,你是在_vti_bin/authentication.asmx

如果你已经是我只能建议这个,因为我不知道ASI是否正确地登录信息。尝试将它放在你的SOAP消息手动像这样:(从here

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
    <Login xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
     <username>USERNAME</username> 
     <password>PASSWORD</password> 
    </Login> 
    </soap:Body> 
</soap:Envelope> 

这应返回你需要使用的网络服务,其余的登录cookie。

编辑:还有一件事,你需要设置你的SP服务器使用表单身份验证,而不是NTLM身份验证(这是默认值)。

+0

嗯..一定有一个错误。唯一的想法是服务器返回idt this:<?xml version =“1.0”encoding =“utf-8”?> soap:客户端无法无需有效的操作参数即可处理请求。请提供有效的肥皂动作。 user1913839

0

看着你的SOAP信封和错误信息,我认为你在请求中缺少SOAPAction标题。

下面的代码显示了如何创建获取Sharepoint实例中所有列表的请求的示例。我正在使用AFNetworking,有些部分可能不适用于ASIHTTPRequest框架。

... 

NSMutableURLRequest *request = [self requestWithMethod:@"POST" 
                path:@"_vti_bin/Lists.asmx" 
              parameters:nil]; 

NSString *soapEnvelope = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
    @"<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/\">" 
    @"<soap:Body>" 
    @"<GetListCollection xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" />" 
    @"</soap:Body>" 
    @"</soap:Envelope>"; 

// Set headers 
[request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[request setValue:@"http://schemas.microsoft.com/sharepoint/soap/GetListCollection" forHTTPHeaderField:@"SOAPAction"]; 

// Content length 
NSString *contentLength = [NSString stringWithFormat:@"%d", soapEnvelope.length]; 
[request setValue:contentLength forHTTPHeaderField:@"Content-Length"]; 

// Set body 
[request setHTTPBody:[soapEnvelope dataUsingEncoding:NSUTF8StringEncoding]]; 

... 

但是,正如蒂姆所说,在使用这种方法之前,您必须进行身份验证。

有几种认证机制,Tim或NTLM(以及其他)描述的上述Forms声明。您必须检查Sharepoint实例的配置方式,或者如果您无法控制服务器的配置,则可能支持多种机制。