【asp.net小札记】页面后台Post数据并接收返回数据

这篇博客详细记录了如何在ASP.NET中实现从Default.aspx页面发送POST请求到Default2.aspx,并接收返回数据的过程。通过查看提供的后台代码,可以了解到具体的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本程序设计到两个页面:Default.aspx和Default2.aspx ,其中Default.aspx页面是Post数据的页面

直接贴出后台代码:

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextBox1.Text = PostData();
    }
    //Post数据并接收
    private string PostData()
    {
        string result = string.Empty;//接受返回的数据
        byte[] buffer = new byte[0];//存储发送的数据
        buffer= System.Text.Encoding.Default.GetBytes("username=glm&pwd=12345");

        HttpWebRequest request = WebRequest.Create("http://localhost:52089/WebSite1/Default2.aspx") as HttpWebRequest;
        request.Method = "PO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值