Hi Julie,
I have got the rtFa and FedAuthcookies & requestDigest and I am able to successfully authenticate. But while uploading the file to SharePoint I am getting the below error,
"<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2130575251, System.Runtime.InteropServices.COMException</m:code><m:message xml:lang="en-US">The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</m:message></m:error>"
My sharepoint link : https://<name>.sharepoint.com/teams/SharePointTest2/Shared%20Documents/Forms/AllItems.aspx
I am using libcurl to post the request.
*int main()
{
CURL *c = curl_easy_init();
struct curl_slist list = NULL;
struct response res;
init_response(&res);
list = curl_slist_append(list, "Content-Type:text/plain");
list = curl_slist_append(list, "X-RequestDigest:value");
list = curl_slist_append(list, "Cookie:rtFa=value;FedAuth=value");
curl_easy_setopt(c, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(c, CURLOPT_URL,"https://<name>.sharepoint.com/teams/SharePointTest2/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files/Add(url='DSsanjay.txt',%20overwrite=true)";);
curl_easy_setopt(c, CURLOPT_POSTFIELDS, "THis is file data.. Writing...");
curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(c, CURLOPT_WRITEDATA,&res);
curl_easy_setopt(c, CURLOPT_VERBOSE, 1L);
curl_easy_perform(c);
}
output:
POST /teams/SharePointTest2/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files/Add(url='DSsanjay.txt',%20overwrite=true) HTTP/2
Host: <name>.sharepoint.com
accept: /
content-type:text/plain
x-requestdigest:value
cookie:rtFa=value;FedAuth=value
content-length: 30
Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
We are completely uploaded and fine
< HTTP/2 403
< cache-control: private, max-age=0
< content-type: application/xml;charset=utf-8
< expires: Thu, 04 Feb 2021 09:37:01 GMT
< last-modified: Fri, 19 Feb 2021 09:37:01 GMT
< vary: Origin
< server: Microsoft-IIS/10.0
< set-cookie: rtFa=value; path=/; secure; HttpOnly
< set-cookie: FedAuth=value; path=/; secure; HttpOnly
< x-sharepointhealthscore: 1
< dataserviceversion: 3.0
< x-aspnet-version: 4.0.30319
< sprequestguid: 32tetc9f-f0cd-b000-de6a-c7515b894761
< request-id: 32tetc9f-f0cd-b000-de6a-c7515b894761
< ms-cv: n6y9Ms3tALDeasdRW4lHYQ.0
< x-requestdigest: value
< strict-transport-security: max-age=31536000
< x-frame-options: SAMEORIGIN
< content-security-policy: frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com .powerapps.com .yammer.com .officeapps.live.com .stream.azure-test.net .microsoftstream.com;
< x-powered-by: ASP.NET
< microsoftsharepointteamservices: 16.0.0.21003
< x-content-type-options: nosniff
< x-ms-invokeapp: 1; RequireReadOnly
< p3p: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
< date: Fri, 19 Feb 2021 09:37:01 GMT
<
Connection #0 to host <name>.sharepoint.com left intact
Output = <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2130575251, System.Runtime.InteropServices.COMException</m:code><m:message xml:lang="en-US">The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</m:message></m:error>*
Am I doing something wrong here?
Please help me out.
Regards,
Sanjay