惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - Hyke

借助Elecard MPEG2 Decoder的Easy RealMedia Tools可以成功转MPEG为RMVB 自己总结的如何用C#查找webBrowser页面中input的checkbox的checked属性! - Hyke - 博客园 C#中将字符串转成 Base64 编码 C#-对称加密的一个例子 SharpDevelop的如何支持中文? 今天初步摸索了一下如何创建新的XML文件 求助:有没有PDF分析并显示的相关类啊? 求助:有什么控件可以显示PDF文件啊? [我的重大收获]C#WinForm实现URI对汉字进行编码! [总结]如何让文本框自动显示最新加入的内容呢?(C#) - Hyke - 博客园 [原创]小测:是易语言快,还是.NET快啊? [原创]自做小软件初步测试Access与SQLite数据库执行效率(C#) [推荐软件]QQ自动登录器1.6.1版正式发布! [转]如何高效使用SQLite .net (C#) [转]使用SQLite进行网站搜索 C# 创建新的SQlite数据库Database(两个方法) [转]SQLite数据库与其它一些数据库的性能比较 [转]在ppt中插入RealPlayer文件 Subtitle Workshop使用教程
[原创]C#.NET网络编程POST数据到网站
Hyke · 2007-06-26 · via 博客园 - Hyke

[原创]C#.NET网络编程POST数据到网站
今天制作了一个投票软件,主要是POST指定数据到指定页面来使后台的票数计算自动增加。
下面我就把我的代码贴出来。为了安全,我隐藏了所有相关的真实网址。

下面首先是命名空间的引用:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;//访问数据流,网页回传的都先是数据流
using System.Text;
using System.Text.RegularExpressions;//正则表达式用来验证回传的网页是否包含目标数据
using System.Windows.Forms;
using System.Net;//必须,对网页的访问通过这个命名空间来实现的

接着是一个函数来实现,为了安全,隐藏了敏感数据(使用星号)

 public Boolean VoteOnce()
        
{
            
//创建HttpWebRequest发送请求用
            HttpWebRequest hwrq = (HttpWebRequest)WebRequest.Create("http://www.***.com/***/***.asp?***=***&***=***");
            
//下面是相关数据头和数据发送方法
            hwrq.Accept = "application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
            hwrq.Referer 
= "http://www.***.com/***/***.asp?***=***&***=***";
            hwrq.ContentType 
= "application/x-www-form-urlencoded";
            hwrq.UserAgent 
= "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; MAXTHON 2.0)";
            hwrq.KeepAlive 
= true;
            hwrq.Method 
= "POST";
            
//下面发送数据,使用MiniSniffer来抓包分析应该发送什么数据
            string PostStr = "*=****%**&****=*";
            ASCIIEncoding ASC2E 
= new ASCIIEncoding();
            
byte[] bytePost = ASC2E.GetBytes(PostStr);//把要发送的数据变成字节
            hwrq.ContentLength = bytePost.Length;
            
//下面是发送数据的字节流
            Stream MyStream = hwrq.GetRequestStream();
            MyStream.Write(bytePost, 
0, bytePost.Length);
            MyStream.Close();
//记得要结束字节流啊
            
//创建HttpWebResponse实例
            HttpWebResponse hwrp = (HttpWebResponse)hwrq.GetResponse();
            StreamReader MyStreamR 
= new StreamReader(hwrp.GetResponseStream(), Encoding.Default);
            
string result = MyStreamR.ReadToEnd();
            Boolean r
=false;
            
if (Regex.IsMatch(result, "成功")==true)
            
{
                r 
= true;
            }

            MyStreamR.Close();
            
return r;
        }