ios - How to write to Sharepoint 2013 list using the Rest API -


i have been stuck week now, want write sharepoint list, usin rest api provide. api looks this, http://site/_api/lists, , here can read , write depending on append url, can read lists without issues, have issues when have write.

i supposed send in content-type, accept, x-requestdigest headers, , post body when write list. code

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"]; 

this construct headers request. , how handle sending of request

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]; } 

this happens after have authenticated sharepoint, have noticed during debugging setwillsendrequestforauthenticationchallengeblock never gets called again, looks need send authentication information via headers now, think request digest for, doesnt cause still don't through.

error message server is

<?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 page invalid , might corrupted. please use web browser's button try operation again.</m:message> </m:error> 

thanks in advance :)

i can't find answer in internet. solved in non recommended way. made requisition using method page in sharepoint application. in return, have tag request digest value. used in way, in post requisition:

[headers setvalue:@"0x175481c0d6d79a7534a0992e528a5b7d36c80c41c01cbee55efb256fa99e1ef551f755baae07e692ade757290f1acca11b560f71338de4aa7781adc90cdc5249,11 jun 2015 18:22:18 -0000" forkey:@"x-requestdigest"];


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -