zoukankan      html  css  js  c++  java
  • C# POST数据到指定页面,并跳转至该页面

    1.     /// <summary>
    2.     /// 跨页面POST数据
    3.     /// </summary>
    4.     public class RemotePost : Dictionary<string, string>
    5.     {
    6.         /// <summary>
    7.         /// 提交HTTP POST请求
    8.         /// </summary>
    9.         /// <param name="url">请求目标地址</param>
    10.         /// <param name="isBackable">可选参数,是否可通过浏览器回退按钮退到本提交页面</param>
    11.         public void Submit(string url, bool isBackable = true)
    12.         {
    13.             HttpResponse response = System.Web.HttpContext.Current.Response;
    14.             response.Clear();
    15.             if (isBackable)
    16.             {
    17.                 response.Write("<html><head></head><body onload="pageload();">");
    18.                 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>");
    19.                 response.Write("<input id="hidBackUrl" type="hidden" value="" />");
    20.             }
    21.             else
    22.             {
    23.                 response.Write("<html><head></head><body onload="document.form1.submit();">");
    24.             }
    25.             response.Write(string.Format("<form name="form1" method="post" action="{0}">", url));
    26.             foreach(string key in this.Keys)
    27.             {
    28.                 response.Write(string.Format("<input name="{0}" type="hidden" value="{1}" />", key, this[key]));
    29.             } 
    30.             response.Write("</form></body></html>");
    31.             response.End();
    32.         }
    33.     }
    使用方法非常简单

    1. var post = new CtripSZ.Frameworks.Net.RemotePost();
    2. post.Add("GUID", Guid.NewGuid().ToString());
    3. post.Submit("./Receive.aspx");
     
     
    原文地址:http://blog.chinaunix.net/uid-20049824-id-3348117.html
  • 相关阅读:
    python函数的基本语法<三>
    python函数的基本语法<二>
    python中文件的基础操作
    python模块——configparser
    python模块——psutil
    python中程序的异常处理
    python——协程
    hbuilder 开发app 自动升级
    C# datagridview 这是滚动条位置
    C# 小知识点记录
  • 原文地址:https://www.cnblogs.com/niaowo/p/3464475.html
Copyright © 2011-2022 走看看