HttpWebRequest提交(Post)数据
protected void Page_Load(object sender, EventArgs e) { string sql = "select top 1 * from [user] order by userid asc"; DataTable dt = DBUtility.SQLHelperJJ3.Query(sql).Tables[0]; string type = "0"; string username = dt.Rows[0]["username"].ToString(); string password = dt.Rows[0]["password"].ToString(); string email = dt.Rows[0]["email"].ToString(); this.HttpPost(type, username, password, email); } private void HttpPost(string type, string username, string password, string email) { string content = "type=" + type + "&username=" + username + "&password=" + password + "&email=" + email; string url = "http://localhost/php/index.php?Action=BatchRegist"; try { //获取提交的字节 byte[] bs = Encoding.UTF8.GetBytes(content); //设置提交的相关参数 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = bs.Length; //提交请求数据 Stream reqStream = req.GetRequestStream(); reqStream.Write(bs, 0, bs.Length); reqStream.Close(); //接收返回的页面,必须的,不能省略 WebResponse wr = req.GetResponse(); System.IO.Stream respStream = wr.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8")); string t = reader.ReadToEnd(); System.Web.HttpContext.Current.Response.Write(t); wr.Close(); } catch (Exception ex) { System.Web.HttpContext.Current.Response.Write("异常在getPostRespone:" + ex.Source + ":" + ex.Message); } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
2016-05-23 用IIS配置反向代理
2016-05-23 authorization配置
2013-05-23 wordpress改变ip或域名
2013-05-23 ubuntu ip设置