C# ASP.net get 和POST

1.服务器端。

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPost=string.Empty;
            try
            {
                 strPost= Request["postName"];
            }
            catch
            {
            }
            string strGet=string.Empty;
            try
            {
               strGet = Request.QueryString["getName"].ToString();
            }
            catch
            {
            }
            StreamWriter swLog= new StreamWriter(Server.MapPath(".") + "//logs.shtml", true, Encoding.UTF8);//所有保存历史数据
            FileInfo filelogs = new FileInfo(Server.MapPath(".") + "//logs.shtml");
            if (filelogs.Length / (1024 * 1024) > 9)//当文件大于10M时,将文件删除。
            {
                filelogs.Delete();
            }
            swLog.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "-------------------------------------------------------");
            swLog.WriteLine("Post Value://" + strPost);
            swLog.WriteLine("Get Value://" + strGet);
            swLog.Close();
          
            StreamWriter swFresh = new StreamWriter(Server.MapPath(".") + "//fresh.shtml", false, Encoding.UTF8);//显示最新数据
            swFresh.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "--------------------------------------------");
            swFresh.WriteLine("Post Value://" + strPost);
            swFresh.WriteLine("Get Value://" + strGet);
            swFresh.Close();
        
        }
    }

 

2.客户端(winFrom)

WebClient webclient= new WebClient();

System.Collections.Specialized.NameValueCollection PostDatas = new System.Collections.Specialized.NameValueCollection();
                        PostDatas.Add(strPost, msg);
                        webclient.UploadValues("http://defualt.aspx?getName=oookk","POST", PostDatas);

 

3.小结:

  其实保存到log这部分可以稍作修改,可以做为程序的捕获异常的LOG档。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值