Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. namespace Winsoft.GOV.Auth.Demo
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. PostMethd();
  14. Console.ReadKey();
  15. }
  16. public static void PostMethd()
  17. {
  18. HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.lszszw.gov.cn/OAuth/api/Message");
  19. Encoding encoding = Encoding.UTF8;
  20. string param = "{\"OpenId\":\"oIeaexOZUPG-953Ci3wsjy_KReDU\",\"Content\":\"hello world\"}";
  21. byte[] bs = Encoding.UTF8.GetBytes(param.ToString());
  22. //byte[] bs = new byte[]{};
  23. string responseData = String.Empty;
  24. req.Method = "POST";
  25. req.ContentType = "application/json;charset=utf-8";
  26. req.ContentLength = bs.Length;
  27. //return;
  28. using (Stream reqStream = req.GetRequestStream())
  29. {
  30. reqStream.Write(bs, 0, bs.Length);
  31. reqStream.Close();
  32. }
  33. using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
  34. {
  35. Console.WriteLine(response.StatusCode);
  36. }
  37. }
  38. }
  39. }