我几乎做了一个API来使用Sharepoint Web Services,除了删除项目部分外,一切正常。
我正在使用Lists.asmx web服务,并且正在调用方法UpdateListItems。
我的请求如下:
<?xml version="1.0" encoding="utf-8"?>
<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">
<soap12:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>Shared Documents</listName>
<updates><Batch OnError="Continue" ListVersion="1" ><Method ID='1' Cmd='Delete'><Field Name='ID'>99</Field></Method></Batch></updates>
</UpdateListItems>
</soap12:Body>
</soap12:Envelope>
响应显示以下错误:
<soap:Reason>
<soap:Text xml:lang="en">Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown
</soap:Text></soap:Reason>
<detail>
<errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</errorstring>
<errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x8102006d</errorcode>
任何想法如何解决这个问题?
答案 0 :(得分:2)
经过大量测试和谷歌搜索,我发现从创建,更新或删除的Web服务收到此错误。错误显示是因为在头文件中我没有包含SOAPAction。
您可以查看我找到解决方案的博客上的详细信息
更改请求以包含以下代码后,安全错误消失了。
NSString *soapAction = [NSString stringWithFormat:@"http://schemas.microsoft.com/sharepoint/soap/%@", method];
[theRequest addValue:serverName forHTTPHeaderField:@"Host"];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Lenght"];
[theRequest addValue:soapAction forHTTPHeaderField:@"SOAPAction"];
[theRequest setHTTPMethod:@"POST"];
我希望这个答案会对某人有所帮助。