gpt4 book ai didi

ios - 如何使用 Rest API 写入 Sharepoint 2013 列表

转载 作者:行者123 更新时间:2023-11-29 02:05:45 25 4
gpt4 key购买 nike

我已经被困了将近一个星期了,我想使用他们提供的 rest api 写入 SharePoint 列表。 API 看起来像这样,http://site/_api/lists ,从这里我可以根据我附加到我的 url 的内容进行读写,我可以毫无问题地从列表中读取,但是当我必须写的时候我会遇到问题。

我应该在写入列表时发送 Content-Type、Accept、X-requestDigest header 和帖子正文。我的代码

NSString *deviceToken = [self getDeviceTokenFromCoreData];
NSString *postData = [NSString stringWithFormat:@"{ \"__metadata\": { \"type\": \"SP.Data.TestListItem\" }, \"Title\": \"Test Title\" }"];

NSData *methodBodyData = [postData dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *jsonString = [NSJSONSerialization JSONObjectWithData:methodBodyData options:0 error:&error];
NSString *acceptType = @"application/json;data=verbose";
NSString *requestDigest = _requestDigest;


NSURL *subscribeURL = [[NSURL alloc] initWithString:subscribeUrlString];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:subscribeURL];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:jsonString];
[theRequest setValue:acceptType forHTTPHeaderField:@"Accept"];
[theRequest setValue:acceptType forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:requestDigest forHTTPHeaderField:@"X-RequestDigest"];

这是我为请求构建 header 的地方。这就是我处理请求发送的方式

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest];

[operation setWillSendRequestForAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
// if (challenge.previousFailureCount == 0) {

NSLog(@"%@", challenge.protectionSpace);
NSURLCredential *creds = [NSURLCredential credentialWithUser:userName
password:userPass
persistence:NSURLCredentialPersistenceForSession];

[[challenge sender] useCredential:creds forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

//Handle Success

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

//Handle failure
}];

[operation start];
}

这发生在我对 sharepoint 进行身份验证之后,我注意到在调试期间 setWillSendRequestForAuthenticationChallengeBlock 再也不会被调用,看起来我现在需要通过 header 发送身份验证信息,这就是我认为请求摘要的用途,但是这无济于事,因为我仍然没有通过。

我从服务器得到的错误信息是

<?xml version="1.0" encoding="utf-8"?>
<m:error
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-2130575251, Microsoft.SharePoint.SPException</m:code>
<m:message xml:lang="en-US">The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again.</m:message>
</m:error>

提前致谢:)

最佳答案

我在互联网上找不到任何答案。我以不推荐的方式解决了。我使用 GET 方法向共享点应用程序中的页面提出了申请。在返回中,我有一个带有请求摘要值的标签。我在我的 POST 请求中以这种方式使用它:

[headers setValue:@"0x175481C0D6D79A7534A0992E528A5B7D36C80C41C01CBEE55EFB256FA99E1EF551F755BAAE07E692ADE757290F1ACCA11B560F71338DE4AA7781ADC9 0CDC5249,2015 年 6 月 11 日 18:22:18 -0000"forKey:@"X-RequestDigest"];

关于ios - 如何使用 Rest API 写入 Sharepoint 2013 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29815445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com