andrew4582

SendJson

Jul 15th, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1.         static string SendJson(string url, string data)
  2.         {
  3.             var httpReq = (HttpWebRequest) WebRequest.Create(url);
  4.             httpReq.ContentType = "application/json";
  5.             httpReq.Method = "POST";
  6.             using (var writer = new StreamWriter(httpReq.GetRequestStream()))
  7.             {
  8.                 writer.Write(data);
  9.                 writer.Flush();
  10.                 writer.Close();
  11.  
  12.                 var httpResp = (HttpWebResponse) httpReq.GetResponse();
  13.                 using (var reader = new StreamReader(httpResp.GetResponseStream()))
  14.                     return reader.ReadToEnd();
  15.             }
  16.         }
Advertisement
Add Comment
Please, Sign In to add comment