•     /// <summary>
  •     /// 跨页面POST数据
  •     /// </summary>
  •     public class RemotePost : Dictionary<string, string>
  •     {
  •         /// <summary>
  •         /// 提交HTTP POST请求
  •         /// </summary>
  •         /// <param name="url">请求目标地址</param>
  •         /// <param name="isBackable">可选参数,是否可通过浏览器回退按钮退到本提交页面</param>
  •         public void Submit(string url, bool isBackable = true)
  •         {
  •             HttpResponse response = System.Web.HttpContext.Current.Response;
  •             response.Clear();
  •             if (isBackable)
  •             {
  •                 response.Write("<html><head></head><body onload=\"pageload();\">");
  •                 response.Write("<script language=\"javascript\">function pageload(){if(document.getElementById('hidBackUrl').value.length==0){document.getElementById('hidBackUrl').value=document.referrer;document.form1.submit();}else{location.href=document.getElementById('hidBackUrl').value;}}</script>");
  •                 response.Write("<input id=\"hidBackUrl\" type=\"hidden\" value=\"\" />");
  •             }
  •             else
  •             {
  •                 response.Write("<html><head></head><body onload=\"document.form1.submit();\">");
  •             }
  •             response.Write(string.Format("<form name=\"form1\" method=\"post\" action=\"{0}\">", url));
  •             foreach(string key in this.Keys)
  •             {
  •                 response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\" />", key, this[key]));
  •             } 
  •             response.Write("</form></body></html>");
  •             response.End();
  •         }
  •     }
  • 使用方法非常简单

  • var post = new CtripSZ.Frameworks.Net.RemotePost();
  • post.Add("GUID", Guid.NewGuid().ToString());
  • post.Submit("./Receive.aspx");
  •  
     
    原文地址:http://blog.chinaunix.net/uid-20049824-id-3348117.html

    相关文章:

    • 2021-10-13
    • 2021-10-02
    • 2022-12-23
    • 2022-12-23
    • 2021-12-19
    猜你喜欢
    • 2022-02-19
    • 2020-06-08
    • 2022-12-23
    • 2021-06-21
    • 2021-11-20
    • 2021-08-01
    相关资源
    相似解决方案