HttpHandler.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. using System.Text;
  6. using System.Web;
  7. using UAS_LabelMachine.Entity;
  8. namespace UAS_LabelMachine.PublicMethod
  9. {
  10. public class HttpHandler : IHttpHandler
  11. {
  12. /// <summary>
  13. /// 您将需要在网站的 Web.config 文件中配置此处理程序
  14. /// 并向 IIS 注册它,然后才能使用它。有关详细信息,
  15. /// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
  16. /// </summary>
  17. public bool IsReusable
  18. {
  19. // 如果无法为其他请求重用托管处理程序,则返回 false。
  20. // 如果按请求保留某些状态信息,则通常这将为 false。
  21. get { return true; }
  22. }
  23. public void ProcessRequest(HttpContext context)
  24. {
  25. }
  26. public static bool CheckUserLogin(string UserName, string PassWord, string Master, out string oMsg)
  27. {
  28. oMsg = "";
  29. try
  30. {
  31. string url = DataHelper.ERPAddesss + "mobile/login.action";//html调用的地址
  32. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
  33. if (webrequest == null)
  34. {
  35. return false;
  36. }
  37. webrequest.Method = "POST";
  38. webrequest.Timeout = 1000;
  39. webrequest.ContentType = "application/x-www-form-urlencoded";
  40. System.Collections.Hashtable pars = new System.Collections.Hashtable();
  41. pars.Add("username", UserName);
  42. pars.Add("password", PassWord);
  43. pars.Add("master", Master);
  44. string buffer = "";
  45. //发送POST数据
  46. if (!(pars == null || pars.Count == 0))
  47. {
  48. foreach (string key in pars.Keys)
  49. {
  50. buffer = buffer + "&" + key + "=" + pars[key].ToString();
  51. }
  52. byte[] data = Encoding.UTF8.GetBytes(buffer);
  53. using (Stream stream = webrequest.GetRequestStream())
  54. {
  55. stream.Write(data, 0, data.Length);
  56. }
  57. }
  58. string[] values = webrequest.Headers.GetValues("Content-Type");
  59. WebResponse myResponse = webrequest.GetResponse();
  60. using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
  61. {
  62. StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
  63. string Content = newReader.ReadToEnd();
  64. Dictionary<string, object> dic = new Dictionary<string, object>();
  65. dic = BaseUtil.ToDictionary(Content);
  66. if (!dic.ContainsKey("erpaccount"))
  67. {
  68. oMsg = dic["reason"].ToString();
  69. return false;
  70. }
  71. newReader.Close();
  72. }
  73. }
  74. catch (Exception ex)
  75. {
  76. LogManager.DoLog(ex.Message.ToString());
  77. }
  78. return true;
  79. }
  80. public static bool GenDownLoadLinK(string Inoutno)
  81. {
  82. SystemInf.dh.ExecuteSql("delete from ProdDownLink where pl_inoutno='" + Inoutno + "'", "delete");
  83. SystemInf.dh.ExecuteSql("insert into ProdDownLink(pl_inoutno,pl_outboxcode) select distinct '" + Inoutno + "',pib_outboxcode1 from prodiobarcode where pib_inoutno='" + Inoutno + "'", "insert");
  84. SystemInf.dh.GetConfig("DownLoadLink", "Prodinout!Down");
  85. string url = SystemInf.dh.GetConfig("DownLoadLink", "Prodinout!Down") + "/common/form/reqDemo.action?Pi_inoutno=" + Inoutno;//html调用的地址
  86. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
  87. try
  88. {
  89. if (webrequest == null)
  90. {
  91. return false;
  92. }
  93. WebResponse myResponse = webrequest.GetResponse();
  94. }
  95. catch (Exception e)
  96. {
  97. LogManager.DoLog(e.Message + e.StackTrace);
  98. }
  99. return true;
  100. }
  101. }
  102. }