asp.net本质论基础篇 get请求与post请求

get post请求
1.首先建个文件夹 将建的东西都放在一个文件夹下
(1)建html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<!--表单:收集用户数据-->
<form method="get" action="AddInfo.ashx">
用户名:<input type="text" name="txtName" /><br />
密码:<input type="password" name="txtPwd" /><br />
<input type="submit" value="提交" />
</form>
</body>
</html>

在这里插入图片描述(2)建个一般处理程序

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

using System;
using System.Web;
using System.IO;
public class ShowAdd : IHttpHandler {
    //用户先访问showAdd.ashx这个一般处理程序  一般处理程序读取模板文件html  然后把读取后的内容返回给浏览器
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        //读取模板文件
        string filepath=context.Request.MapPath("Add.html");
        string filecontent=File.ReadAllText(filepath);
        context.Response.Write(filecontent);
        //收集完数据,用户点按钮把输入的数据以get方式发送到AddInfo.ashx这个页面 
        //AddInfo这个一般处理程序开始发送一个get请求,并且把表单里的数据传到AddInfo里面    Add和AddInfo要在同一文件夹下
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

在这里插入图片描述
(3)在建一个一般处理程序

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

using System;
using System.Web;

public class AddInfo : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";  //Response输出
        
        //get方式
        //string username = context.Request.QueryString["txtName"];//接收的是表单元素name的值   Request接收的意思
        //string  userPwd= context.Request.QueryString["txtPwd"];
        //post方式
        string username = context.Request.Form["txtName"];
        string userPwd = context.Request.Form["txtPwd"];
        context.Response.Write("用户名是:"+username+",密码是:"+userPwd);
        //传的方式不同  get方式是把数据放在地址栏里的,post方式是把数据放在请求报文里的
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

在这里插入图片描述

总结内容
在这里插入图片描述
学asp.net本质论 get post 后面会经常用,暂时理解一下,不需要刻意记

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值