//Json Data
var pairs = new NameValueCollection()
{
{ "bypassCRM", "true"},
{ "FirstName", "Vikram"},
{ "LastName", "Tupe"},
};
byte[] response = null;
using (WebClient client = new WebClient())
{//Attach Headers if any.... (Below Authorization is custom header required in my case)
client.Headers["Authorization"] = "AuthToken";
response = client.UploadValues(url, "DELETE", pairs);
}
var text = System.Text.Encoding.UTF8.GetString(response);
/* Above is equivalent to following web request/ json */
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "DELETE";
httpWebRequest.Headers.Add("Authorization:AuthToken");
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
//Json Data
string json = "{\"FirstName\":\"" + "Vikram" + "\"," +
"\"LastName\":\"" + "Test" + "\"," +
"\"bypassCRM\":\"true\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream())){
text = streamReader.ReadToEnd();
}
}
No comments:
Post a Comment