Forum Discussion
Paolo Ajani
May 08, 2018Copper Contributor
Suddenly getting 401 error accessing SPS Online
Hi All. Since yesterday my c# code stopped working when trying to access SPS Online (and Project PWA in specific) through HttpWebRequest interface while CSOM continue to work as expected. in both c...
- May 09, 2018
Hi,
Just FYI, here is the piece of updated code i have used and now it is working fine.
The one in BOLD is the new line of code that i have used to make it working.
SecureString passWord = new SecureString();
foreach (char c in m_Password.ToCharArray()) passWord.AppendChar(c);
var credentials = new SharePointOnlineCredentials("UserName, passWord);
string metaDataURL = "ProjectOnlineURL";
var req = (HttpWebRequest)WebRequest.Create(metaDataURL);
req.Credentials = credentials;req.Headers["X-FORMS_BASED_AUTH_ACCEPTED"] = "f";
req.Headers.Add(HttpRequestHeader.Cookie, credentials.GetAuthenticationCookie(new Uri(metaDataURL)));
var resp = (HttpWebResponse)req.GetResponse();Regards,
Sunil G.
Have you decorated your code as suggested here: https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online?
Paolo Ajani
May 09, 2018Copper Contributor
Thank you Juan Carlos.
In this specific case it looks like a specific problem with HttpWebRequest authentication while throttling impacts CSOM as well.
Anyway it's a very good point too take care of.
In this specific case it looks like a specific problem with HttpWebRequest authentication while throttling impacts CSOM as well.
Anyway it's a very good point too take care of.