ASP get请求,post请求

动态页面替换文本。Replace

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        //获取要操作的模板的路径.
        string filePath = context.Request.MapPath("ShowInfo.html");//获取文件的物理路径。在Asp.net中,对文件或文件夹进行操作一定要获取物理路径。
        //读取模板文件中的内容。
       string fileContent=File.ReadAllText(filePath);
        //用户具体的数据替换模板文件中的占位符。
       fileContent = fileContent.Replace("$name","替换成名字").Replace("$pwd","123");
        //将替换后的内容输出给浏览器。
       context.Response.Write(fileContent);
       context.Response.Write("<b>adfsdf</b>");
    }

get请求,post请求。服务器端接收数据。

<%@ WebHandler Language="C#" Class="AddInfo" %>

using System;
using System.Web;

public class AddInfo : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        ///string userName=context.Request.QueryString["txtName"];//get请求接收的是表单元素name属性的值
       // string userPwd=context.Request.QueryString["txtPwd"];

        string userName = context.Request.Form["txtName"];  //post请求
        string userPwd = context.Request.Form["txtPwd"];
        
        context.Response.Write("用户名是:"+userName+",密码是:"+userPwd);
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值