There is a scenario where we have Project Server hosted on different farm but we need to fetch projects data through rest API from a SharePoint site collection hosted in another farm. We have tried this from console application and it was working fine. But when we tried through Sandbox Solution it is throwing security exception, we have also tried to access through jQuery ajax but not able to fetch as we are getting the below error
Failed to load resource: the server responded with a status of 401 (Unauthorized)
XMLHttpRequest cannot load https://<sitename>/PWA/_api/ProjectData/Projects/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://<siteurl>' is therefore not allowed access. The response had HTTP status code 401.</siteurl></sitename>
<sitename><siteurl></siteurl></sitename>
<sitename><siteurl></siteurl></sitename>
code for console application was
Uri uri = new Uri("https://xx.mysite.com/_api/web/lists/GetByTitle('TeamList')/items"); NetworkCredential cred = new NetworkCredential("xxx", "xxx", "xx"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.ContentType = "application/json;odata=verbose"; request.Headers["X-RequestDigest"] = GetFormDigest(cred); request.Accept = "application/json;odata=verbose"; // request.ContentLength = itemXML.Length; request.Credentials = cred; request.Accept = "application/json;odata=verbose"; request.Method = "POST"; string stringData = "{ '__metadata': { 'type': 'SP.ListItem' }, 'Title': 'Hello World' }"; request.ContentLength = stringData.Length; StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(stringData); writer.Flush(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream());
It's very urgent so any help would be appreciated.- Edited by Joy_at_time_of_his_life 19 hours 32 minutes ago