public string Post(string url,Request request)
{
try
{
WebRequest webRequest = WebRequest.CreateHttp(url);
string postData = JsonConvert.SerializeObject(request);
byte[] data = Encoding.UTF8.GetBytes(postData);
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
webRequest.ContentLength = data.Length;
using (Stream stream = webRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
string response = string.Empty;
**WebResponse myHttpWebResponse = webRequest.GetResponse();**
//what is the best way to use a secondary url if WebResponse is null..
using (StreamReader sr = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.UTF8))
{
response = sr.ReadToEnd();
}
return response;
}
catch (Exception e)
{
throw e;
}
}