WebResult.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WebManager
  7. {
  8. public class WebResult
  9. {
  10. /// <summary>
  11. /// 数据定义
  12. /// </summary>
  13. private String webServer_IP = "";
  14. private String webServer_Port = "";
  15. private String webServer_Path = "";
  16. private String Url = "";
  17. private const String Post = "Post";
  18. private const String Content_Type= "Content-Type:application/json";
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. /// <param name="ws_ip">WebServer的IP地址</param>
  23. /// <param name="ws_port">WebServer的端口号</param>
  24. /// <param name="ws_path">WebServer的项目名</param>
  25. public WebResult(String ws_ip,String ws_port,String ws_path)
  26. {
  27. this.webServer_IP = ws_ip;
  28. this.webServer_Port = ws_port;
  29. this.webServer_Path = ws_path;
  30. //更新Web网址
  31. Update_Url();
  32. }
  33. /// <summary>
  34. /// 更新Web网址
  35. /// </summary>
  36. private void Update_Url()
  37. {
  38. if (this.webServer_Path.Substring(0, 1) != "/")
  39. {
  40. this.webServer_Path = "/" + this.webServer_Path;
  41. }
  42. this.Url = "http://" + this.webServer_IP + ":" + this.webServer_Port + this.webServer_Path;
  43. }
  44. /// <summary>
  45. /// WebServer的IP地址
  46. /// </summary>
  47. public String WebServer_IP
  48. {
  49. //get { return this.webServer_IP; }
  50. set
  51. {
  52. this.webServer_IP = value;
  53. Update_Url();
  54. }
  55. }
  56. /// <summary>
  57. /// WebServer的端口号
  58. /// </summary>
  59. public String WebServer_Port
  60. {
  61. //get { return this.webServer_IP; }
  62. set
  63. {
  64. this.webServer_Port = value;
  65. Update_Url();
  66. }
  67. }
  68. /// <summary>
  69. /// WebServer的项目名
  70. /// </summary>
  71. public String WebServer_Path
  72. {
  73. //get { return this.webServer_IP; }
  74. set
  75. {
  76. this.webServer_Path = value;
  77. Update_Url();
  78. }
  79. }
  80. public String RequestString(String postString)
  81. {
  82. try
  83. {
  84. String res = HttpRequestHelper.DoRequest(this.Url, Post, Content_Type, postString);
  85. return res;
  86. }
  87. catch
  88. {
  89. return "";
  90. }
  91. }
  92. }
  93. }