zoukankan      html  css  js  c++  java
  • 用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;
                }
              
            }

          
        }
    }

  • 相关阅读:
    [转]rdlc报表中表达式的使用--switch和IIF范例
    [转]关于ASP.NET(C#)程序中TEXTBOX下动态DIV跟随[AJAX应用]
    CodeForces
    NYOJ306 走迷宫(dfs+二分搜索)
    全心全意为人民服务体如今我们软件设计上
    2014年麦克阿瑟基金奖,张益唐入围(62万美金用于个人支配)
    Android中SharedPreferences函数具体解释
    drupal7中CKEditor开启上传图片功能
    JBoss+Ant实现EJB无状态会话bean实例
    c#读取xml文件配置文件Winform及WebForm-Demo具体解释
  • 原文地址:https://www.cnblogs.com/tiancai/p/2938687.html
Copyright © 2011-2022 走看看