Skip to content

Instantly share code, notes, and snippets.

@Msirkovsky
Created November 28, 2016 15:47
Show Gist options
  • Save Msirkovsky/e7e3f73e53fe35dd6538e0f2ca1a9e4f to your computer and use it in GitHub Desktop.
Save Msirkovsky/e7e3f73e53fe35dd6538e0f2ca1a9e4f to your computer and use it in GitHub Desktop.
private string PostRaw(string url, string data)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
request.Method = "POST";
using (var requestWriter = new StreamWriter(request.GetRequestStream()))
{
requestWriter.Write(data);
}
var response = (HttpWebResponse)request.GetResponse();
if (response == null)
throw new InvalidOperationException("GetResponse returns null");
using (var sr = new StreamReader(response.GetResponseStream()))
{
return sr.ReadToEnd();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment