ClickHouseUtil.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.IO;
  2. using System.Net;
  3. using System.Text;
  4. namespace MemberWeb.Commonss
  5. {
  6. public static class ClickHouseUtil
  7. {
  8. static string conentUrl = "http://139.159.192.185:8123/?user=default&password=79B084A8D7363488DEBFA5D151CCC9B1";
  9. public static string HttpClickHouseGet(string url)
  10. {
  11. url = conentUrl + "&query=" + url;
  12. WebRequest myWebRequest = WebRequest.Create(url);
  13. WebResponse myWebResponse = myWebRequest.GetResponse();
  14. myWebRequest.Timeout = 60000;
  15. Stream ReceiveStream = myWebResponse.GetResponseStream();
  16. string responseStr = "";
  17. if (ReceiveStream != null)
  18. {
  19. StreamReader reader = new StreamReader(ReceiveStream, Encoding.UTF8);
  20. responseStr = reader.ReadToEnd();
  21. reader.Close();
  22. }
  23. myWebResponse.Close();
  24. return responseStr;
  25. }
  26. public static string HttpClickHousePost(string body, string contentType)
  27. {
  28. string url = conentUrl;
  29. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  30. httpWebRequest.ContentType = contentType;
  31. httpWebRequest.Method = "POST";
  32. httpWebRequest.Timeout = 20000;
  33. byte[] btBodys = Encoding.UTF8.GetBytes(body);
  34. httpWebRequest.ContentLength = btBodys.Length;
  35. httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
  36. HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  37. StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
  38. string responseContent = streamReader.ReadToEnd();
  39. httpWebResponse.Close();
  40. streamReader.Close();
  41. httpWebRequest.Abort();
  42. httpWebResponse.Close();
  43. return responseContent;
  44. }
  45. }
  46. }