Last post Oct 19, 2016 08:36 AM by PatriceSc
Oct 19, 2016 06:47 AM|rogue1|LINK
How would one change this into a aysnc method it would be called from a webforms ui where it posts json to a method called createcase the url is just
www.domain.com/createcase and there expecting a post of string json which i have already formatted is this routine enough to create that.
public void TransferToSlate(string json, string url)
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
var result = streamReader.ReadToEnd();
Oct 19, 2016 08:36 AM|PatriceSc|LINK
See https://www.asp.net/web-forms/overview/performance-and-caching/using-asynchronous-methods-in-aspnet-45 for a detailed discussion. In
short you'll use the async/await pattern calling the GetResponseAsync and you'll register the returned task.
The important part is likely more when you want to trigger this call (and you don't care at all about the response you'll get ?)