Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Get Request Digest
- HttpWebRequestendpointRequest = (HttpWebRequest)HttpWebRequest.Create("<<site
- url>>/_api/contextinfo");
- endpointRequest.Method = "POST";
- endpointRequest.Accept = "application/json;odata=verbose";
- endpointRequest.ContentType = "application/x-www-form-urlencoded";
- endpointRequest.ContentLength = 0;
- NetworkCredential cred = newSystem.Net.NetworkCredential("username", "password", "domain");
- endpointRequest.Credentials = cred;
- HttpWebResponseendpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
- //Sample Post Command
- HttpWebRequestendpointRequest = (HttpWebRequest)HttpWebRequest.Create("<<REST URL>>");
- endpointRequest.Method = "POST";
- endpointRequest.Accept = "application/json;odata=verbose";
- endpointRequest.ContentType = "application/json;odata=verbose";
- NetworkCredential cred = newSystem.Net.NetworkCredential("username", "password", "domain");
- endpointRequest.Credentials = cred;
- String username = "username";
- String password = "password";
- StringuserPassword = username + ":" + password;
- byte[] byteArrayUP = Encoding.UTF8.GetBytes(userPassword);
- endpointRequest.Headers.Add("Authorization", "Bearer" + byteArrayUP);
- stringpostData = "{ '__metadata': { 'type': 'SP.Data.<<ListTitle>>ListItem' }, 'Column1':
- 'Text1','Column2':'Text2'}";
- byte[] byteArray = Encoding.UTF8.GetBytes(postData);
- // endpointRequest.ContentLength = byteArray.Length;
- endpointRequest.Headers.Add("X-RequestDigest", digest);
- // Get the request stream.
- StreamdataStream = endpointRequest.GetRequestStream();
- // Write the data to the request stream.
- dataStream.Write(byteArray, 0, byteArray.Length);
- // Close the Stream object.
- dataStream.Close();
- HttpWebResponseendpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
Add Comment
Please, Sign In to add comment