本文介绍了使用的WebRequest获取cookies来自动登录到SharePoint Online中,越来越variour错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面这个教程为SharePoint Online中远程身份验证,但我这样做在C#





我可以没有问题STS获得SAML,但我似乎无法发送该令牌到SharePoint才能收到回饼干为了登录英寸下面是我的代码,请原谅任何明显的错误,我是新这个!

  //发送cookie来SPO。令牌是STS。 
字节[] = spbyteArray Encoding.UTF8.GetBytes(theToken);
的WebRequest sprequest = WebRequest.Create(https://login.microsoftonline.com/login.srf?wa=wsignin1.0&rpsnv=2&ct=1335885737&rver=6.1.6206.0&wp=MBI& ; wreply = HTTPS%3A%2F%2Fcamida.sharepoint.com%2F_forms%2Fdefault.aspx&放大器; LC = 1033和ID = 500046&安培; cbcxt =麦和放大器; wlidp = 1&安培;客人= 1);
sprequest.Method =POST;
sprequest.ContentLength = spbyteArray.Length;
sprequest.ContentType =应用/的X WWW的形式,进行了urlencoded
sprequest.Headers.GetType()InvokeMember(ChangeInternal,BindingFlags.NonPublic可|。BindingFlags.Instance | BindingFlags.InvokeMethod,空,sprequest.Headers,新的对象[] {主机,mydomain.sharepoint。 COM});
流spdataStream = sprequest.GetRequestStream();
spdataStream.Write(spbyteArray,0,spbyteArray.Length);
spdataStream.Close();

//从SPO $ B $回应b WebResponse的spresponse = sprequest.GetResponse();
spdataStream = spresponse.GetResponseStream();
StreamReader的吊具=新的StreamReader(spdataStream);

//读取内容。
串spresponseFromServer = spreader.ReadToEnd();

如果我使用URL中的教程中,我得到一个403禁止。我使用的是URL重定向到当我到

任何帮助和建议是极大的赞赏。


解决方案

在自申请的SharePoint,你必须设置用户代理,否则它会返回一个403这条线;

  sprequest.UserAgent =Mozilla的/ 5.0( Windows NT的6.0; RV:12.0)的Gecko / 20100101火狐/ 12.0; 



时的所有花费。


I am following this tutorial to authenticate for Sharepoint Online remotely, but I'm doing it in C#.

http://allthatjs.com/2012/03/28/remote-authentication-in-sharepoint-online/

I can get the SAML from STS with no problem, but I can't seem to send this token to Sharepoint to recieve back the Cookies in order to log in. Below is my code, excuse any glaring errors, I'm new at this!

 //Send cookie to SPO. The token is from STS.
        byte[] spbyteArray = Encoding.UTF8.GetBytes(theToken);
        WebRequest sprequest = WebRequest.Create("https://login.microsoftonline.com/login.srf?wa=wsignin1.0&rpsnv=2&ct=1335885737&rver=6.1.6206.0&wp=MBI&wreply=https%3A%2F%2Fcamida.sharepoint.com%2F_forms%2Fdefault.aspx&lc=1033&id=500046&cbcxt=mai&wlidp=1&guest=1");
        sprequest.Method = "POST";
        sprequest.ContentLength = spbyteArray.Length;
        sprequest.ContentType = "application/x-www-form-urlencoded";
        sprequest.Headers.GetType().InvokeMember("ChangeInternal", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, sprequest.Headers, new object[] { "Host", "mydomain.sharepoint.com" });
        Stream spdataStream = sprequest.GetRequestStream();
        spdataStream.Write(spbyteArray, 0, spbyteArray.Length);
        spdataStream.Close();

        //Get response from SPO
        WebResponse spresponse = sprequest.GetResponse();
        spdataStream = spresponse.GetResponseStream();
        StreamReader spreader = new StreamReader(spdataStream);

        // Read the content.
        string spresponseFromServer = spreader.ReadToEnd();

If I use the URL in the tutorial I get a 403 forbidden. The URL I am using is the one it redirects to when I got to http://mydomain.sharepoint.com

Any help and advice is greatly appreciated.

解决方案

When requesting from SharePoint you have to set the User Agent or else it returns a 403 This line;

 sprequest.UserAgent = "Mozilla/5.0 (Windows NT 6.0; rv:12.0) Gecko/20100101 Firefox/12.0";

Is all it took.

这篇关于使用的WebRequest获取cookies来自动登录到SharePoint Online中,越来越variour错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 02:48