用C# WebClient类 提交数据

用C# WebClient类 提交

WebClient是一个强大的类。

提供向 URI 标识的资源发送数据和从 URI 标识的资源接收数据的公共方法。

这也就意味着可以像网站发送数据。

例如给网站留言,注册用户等等。。。。。。

下面是自动注册的一个功能

具体代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace AutoAcquisitionF
{
    public partial class Form1 : Form
    {
        int id = 20;
        public Form1()
        {
            InitializeComponent();
        }

            private void button2_Click(object sender, EventArgs e)
        {

            this.timer1.Enabled = true;
            this.timer1.Interval = int.Parse(this.intervalTime.Text);
            this.timer1.Tick += new EventHandler(regusers);
            this.id = int.Parse(this.idB.Text);
            this.timer1.Start();

 

           
        }

        void regusers(object sender, EventArgs e)
        {
            // 要提交表单的URI字符串。
            string uriString = "http://www.***.com/UserRegPost.asp";
            Random r = new Random();
            int rint = r.Next(1000);
            string postString = "UserName=test" + (id++) + "";

            WebClient webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            byte[] postData = Encoding.Default.GetBytes(postString);

            byte[] responseData = webClient.UploadData(uriString, "POST", postData);

            string srcString = Encoding.Default.GetString(responseData);
            if (srcString.IndexOf("你注册的用户名") > 0)
            {
                this.html.Text = id+"注册成功" + DateTime.Now.ToString(); ;
            }
            if (id==int.Parse(this.idE.Text))
            {
                this.timer1.Stop();
                this.timer1.Enabled = false;
            }
          
        }

      
    }
}

posted @   甜菜波波  阅读(593)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示