iOS Sharepoint应用登陆错误

3

我正在开发一个iOS iPad应用程序,用于连接Sharepoint。我使用ASIHTTPRequest框架来完成这个任务。我的代码如下:

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禁止错误。为什么呢? 在我看来,我不认为用户名和密码有错。也许请求出了问题?

2个回答

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所说,您必须在使用此方法之前进行身份验证。

有几种身份验证机制,如Tim所述的表单声明或NTLM(以及其他一些)。您必须检查您的Sharepoint实例如何配置,或者如果无法控制服务器的配置,则可能支持多种机制。


0

由于您没有发布您的 URL,我不得不问一下,您是否正在 POST 到 _vti_bin/authentication.asmx

如果您已经这样做了,我只能建议您这样做,因为我不知道 ASI 是否正确地放置了登录信息。尝试手动将其放入 SOAP 消息中,像这样:(来自这里)

<?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身份验证(这是默认值)。

哎呀..一定有错。服务器返回的唯一内容是这个: <?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="" rel = "nofollow noreferrer">http://www.w3.org/2001/XMLSchema">soap:Bodysoap:Fault<faultcode>soap:Client</faultcode><faultstring>无法处理没有有效操作参数的请求,请提供有效的 soap 操作。</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> - user1913839

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接