本文介绍了Sharepoint API将新项目发布到列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hellow
我想用post / rest(C#)命令向List中添加一个新项目SharePoint中。我可以从API获取数据 - >这是有效的。
pw被删除
          SecureString passWord = new SecureString();
          foreach(char c in"" .ToCharArray())
          {
              passWord.AppendChar(c);
          }
          HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("");
          endpointRequest.Method =" GET";
          endpointRequest.Accept =" application / json; odata = verbose";
          endpointRequest.Credentials = new SharePointOnlineCredentials("",passWord);
          endpointRequest.Headers.Add("授权","承载"+""");
          HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
$
         试试
          {
              WebResponse webResponse = endpointRequest.GetResponse();
             流webStream = webResponse.GetResponseStream();
              StreamReader responseReader = new StreamReader(webStream);
              string response = responseReader.ReadToEnd();
           
           
              responseReader.Close();
              Console.ReadLine();
          }¥b $ b           catch(例外X)
          {
$
          }
现在我想要将项目上传到列表中,并且响应是禁止的403
          string json = string.Empty;
          SecureString passWord = new SecureString();
          foreach(char c in"" .ToCharArray())
          {
              passWord.AppendChar(c);
          }
          json =" {\" KlantNr \":\" 2563 \",\" Klant \":\" testmattijs \"}" ;;
          ASCIIEncoding encoder = new ASCIIEncoding();
          byte [] data = encoder.GetBytes(json);
          HttpWebRequest endpointRequest =(HttpWebRequest)HttpWebRequest.Create("");
          endpointRequest.Method =" POST";
          endpointRequest.Accept =" application / json; odata = verbose";
          endpointRequest.ContentType =" application / json; odata = verbose";
          endpointRequest.ContentLength = data.Length;
          endpointRequest.Credentials = new SharePointOnlineCredentials("",passWord);
          endpointRequest.Headers.Add("授权","承载"+""");
       
         试试
          {
             使用(Stream newStream = endpointRequest.GetRequestStream())
              {
                  newStream.Write(data,0,data.Length);
                  newStream.Flush();
                  newStream.Close();
$
                  HttpWebResponse response = endpointRequest.GetResponse()as HttpWebResponse;
              }¥b $ b           }¥b $ b           catch(例外X)
          {
              string s = X.Message.ToString();
          } 
解决方案
Hellow
I want with post/rest (C#) command add a new item to a List in Sharepoint. I Can get data from the API -> this works.
pw are deleted
SecureString passWord = new SecureString();foreach (char c in "".ToCharArray())
{
passWord.AppendChar(c);
}
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Credentials = new SharePointOnlineCredentials("", passWord);
endpointRequest.Headers.Add("Authorization", "Bearer " + "");
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
try
{
WebResponse webResponse = endpointRequest.GetResponse();
Stream webStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
responseReader.Close();
Console.ReadLine();
}
catch (Exception X)
{
}
now I want a upload a item to a list and the respons is Forbidden 403
string json = string.Empty;SecureString passWord = new SecureString();
foreach (char c in "".ToCharArray())
{
passWord.AppendChar(c);
}
json = "{\"KlantNr\":\"2563\",\"Klant\":\"testmattijs\"}";
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] data = encoder.GetBytes(json);
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("");
endpointRequest.Method = "POST";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.ContentType = "application/json;odata=verbose";
endpointRequest.ContentLength = data.Length;
endpointRequest.Credentials = new SharePointOnlineCredentials("", passWord);
endpointRequest.Headers.Add("Authorization", "Bearer " + "");
try
{
using (Stream newStream = endpointRequest.GetRequestStream())
{
newStream.Write(data, 0, data.Length);
newStream.Flush();
newStream.Close();
HttpWebResponse response = endpointRequest.GetResponse() as HttpWebResponse;
}
}
catch (Exception X)
{
string s = X.Message.ToString();
}
解决方案
这篇关于Sharepoint API将新项目发布到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!