Android 从移动设备调用SharePoint Rest

Android 从移动设备调用SharePoint Rest,android,ios,rest,sharepoint,mobile,Android,Ios,Rest,Sharepoint,Mobile,所有的鹿 我面临的问题是如何在我们的移动团队(Android和IOS)中调用SharePoint REST 主要问题是如何实现登录操作 我的sharepoint环境是Windows身份验证,现在我尝试了以下方法 代码1,使用NetworkCredentials,它可以工作,但我认为它不适合移动设备 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://ap.2013.trial.nintex.com/_api/we

所有的鹿

我面临的问题是如何在我们的移动团队(Android和IOS)中调用SharePoint REST

主要问题是如何实现登录操作

我的sharepoint环境是Windows身份验证,现在我尝试了以下方法

代码1,使用NetworkCredentials,它可以工作,但我认为它不适合移动设备

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://ap.2013.trial.nintex.com/_api/web?$select=title");
        request.Accept = "application/json;odata=verbose";
        NetworkCredential myCredential = new NetworkCredential("Justin.Liu1", "3QF0\"gn", "EXT");
        request.Credentials = myCredential;
        WebResponse response = request.GetResponse();
        Stream stream = response.GetResponseStream();
        StreamReader sr = new StreamReader(stream);
        string content = sr.ReadToEnd();
ClientContext ctx = new ClientContext("https://ap.2013.trial.nintex.com/");
        ctx.Credentials = myCredential;
        Web web = ctx.Web;
        ctx.Load(web);
        ctx.ExecuteQuery();
        string title = web.Title;
代码2使用CSOM,我认为这也不适用于移动设备

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://ap.2013.trial.nintex.com/_api/web?$select=title");
        request.Accept = "application/json;odata=verbose";
        NetworkCredential myCredential = new NetworkCredential("Justin.Liu1", "3QF0\"gn", "EXT");
        request.Credentials = myCredential;
        WebResponse response = request.GetResponse();
        Stream stream = response.GetResponseStream();
        StreamReader sr = new StreamReader(stream);
        string content = sr.ReadToEnd();
ClientContext ctx = new ClientContext("https://ap.2013.trial.nintex.com/");
        ctx.Credentials = myCredential;
        Web web = ctx.Web;
        ctx.Load(web);
        ctx.ExecuteQuery();
        string title = web.Title;
代码3使用WebService,但我一直面临401错误

//add web reference
        ctest.Authentication auth = new ctest.Authentication();
        ctest.LoginResult result = auth.Login("EXT\\Justin.Liu1", "3QF0\"gn");

        //or using webrequest
        //Site URL: https://ap.2013.trial.nintex.com
        //Username: EXT\Justin.Liu1
        //Password: 3QF0"gn
        var soapEnv = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
                <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
                  <soap:Body>
                    <Login xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">
                      <username>{0}</username>
                      <password>{1}</password>
                    </Login>
                  </soap:Body>
                </soap:Envelope>","EXT\\Justin.Liu1","3QF0\"gn");
        byte[] data = Encoding.UTF8.GetBytes(soapEnv);
        HttpWebRequest loginRequest = (HttpWebRequest)WebRequest.Create("https://ap.2013.trial.nintex.com/_vti_bin/Authentication.asmx");
        loginRequest.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/Login";
        loginRequest.Method = "POST";
        loginRequest.ContentType = "text/xml; charset=utf-8";
        loginRequest.ContentLength = data.Length;
        Stream requestStream = loginRequest.GetRequestStream();
        requestStream.Write(data, 0, data.Length);
        requestStream.Close();
        WebResponse loginResponse = loginRequest.GetResponse();
        Stream loginStream = loginResponse.GetResponseStream();
        StreamReader lsr = new StreamReader(loginStream);
        string loginContent = lsr.ReadToEnd();
        requestStream.Close();
//添加web引用
ctest.Authentication auth=新的ctest.Authentication();
ctest.LoginResult result=auth.Login(“EXT\\Justin.Liu1”、“3QF0\“gn”);
//或者使用webrequest
//网站网址:https://ap.2013.trial.nintex.com
//用户名:EXT\Justin.Liu1
//密码:3QF0“gn
var soapEnv=string.Format(@)
{0}
{1}
“,”EXT\\Justin.Liu1“,”3QF0 \“gn”);
byte[]data=Encoding.UTF8.GetBytes(soapEnv);
HttpWebRequest loginRequest=(HttpWebRequest)WebRequest.Create(“https://ap.2013.trial.nintex.com/_vti_bin/Authentication.asmx");
loginRequest.Headers[“SOAPAction”]=“http://schemas.microsoft.com/sharepoint/soap/Login";
loginRequest.Method=“POST”;
loginRequest.ContentType=“text/xml;字符集=utf-8”;
loginRequest.ContentLength=数据.Length;
Stream requestStream=loginRequest.GetRequestStream();
requestStream.Write(数据,0,数据长度);
requestStream.Close();
WebResponse loginResponse=loginRequest.GetResponse();
Stream loginStream=loginResponse.GetResponseStream();
StreamReader lsr=新的StreamReader(loginStream);
字符串loginContent=lsr.ReadToEnd();
requestStream.Close();
任何有移动设备经验的人都会帮我一个大忙,谢谢你花时间


贾斯汀

有人帮忙吗?有人帮忙吗?