Guest User

Untitled

a guest
Jan 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //Get Request Digest
  2. HttpWebRequestendpointRequest = (HttpWebRequest)HttpWebRequest.Create("<<site
  3. url>>/_api/contextinfo");
  4. endpointRequest.Method = "POST";
  5. endpointRequest.Accept = "application/json;odata=verbose";
  6. endpointRequest.ContentType = "application/x-www-form-urlencoded";
  7. endpointRequest.ContentLength = 0;
  8. NetworkCredential cred = newSystem.Net.NetworkCredential("username", "password", "domain");
  9. endpointRequest.Credentials = cred;
  10. HttpWebResponseendpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
  11. //Sample Post Command
  12. HttpWebRequestendpointRequest = (HttpWebRequest)HttpWebRequest.Create("<<REST URL>>");
  13. endpointRequest.Method = "POST";
  14. endpointRequest.Accept = "application/json;odata=verbose";
  15. endpointRequest.ContentType = "application/json;odata=verbose";
  16. NetworkCredential cred = newSystem.Net.NetworkCredential("username", "password", "domain");
  17. endpointRequest.Credentials = cred;
  18. String username = "username";
  19. String password = "password";
  20. StringuserPassword = username + ":" + password;
  21. byte[] byteArrayUP = Encoding.UTF8.GetBytes(userPassword);
  22. endpointRequest.Headers.Add("Authorization", "Bearer" + byteArrayUP);
  23. stringpostData = "{ '__metadata': { 'type': 'SP.Data.<<ListTitle>>ListItem' }, 'Column1':
  24. 'Text1','Column2':'Text2'}";
  25. byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  26. // endpointRequest.ContentLength = byteArray.Length;
  27. endpointRequest.Headers.Add("X-RequestDigest", digest);
  28. // Get the request stream.
  29. StreamdataStream = endpointRequest.GetRequestStream();
  30. // Write the data to the request stream.
  31. dataStream.Write(byteArray, 0, byteArray.Length);
  32. // Close the Stream object.
  33. dataStream.Close();
  34. HttpWebResponseendpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
Add Comment
Please, Sign In to add comment