文档章节

get post

D
 DailyDiary
发布于 2017/04/07 12:22
字数 232
阅读 4
收藏 0

get

  //GET 
            string url = "url";
            try
            {
                HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(url);
                Req.CookieContainer = cookie;
                Req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                Req.Accept = "*/*";
             Req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0";
                Req.Method = "GET";

                HttpWebResponse res = (HttpWebResponse)Req.GetResponse();
                Stream stream = res.GetResponseStream();
                StreamReader sr = new StreamReader(stream, Encoding.GetEncoding("GB2312"));
                string strResult = sr.ReadToEnd();
                
                __VIEWSTATE = "";

 

//POST

ttpWebRequest Req = null;
            HttpWebResponse Res = null;
            string url = "url";
            try
            {
                Req = (HttpWebRequest)WebRequest.Create(url);
                Req.CookieContainer = cookie;
                Req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                Req.Referer = "refer";
                Req.Accept = "*/*";
                Req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0";
                Req.Method = "POST";
                Req.AllowAutoRedirect = true;

string strPOST =

"__VIEWSTATE=%2FwEPDwUKMTExOTM4OTA4OGRkahJa4sL9gWLcydx9DZkzEk0ABr0%3D&__VIEWSTATEGENERATOR=FBE090BD&__EVENTVALIDATION=%2FwEdAAl0D4J9xNWB%2BgcnFKWvnZoN4%2FQfLsHQGYVYSXJhGOfKYCKgvRijP5cR7wp7WnFU4dtC8mj0x2qcszeBnohw4I4n65iJzCLHkVO2kGDkjn3iKMyQ43FRB5dc45mq3hyL0EOtZ2K%2B50k8QAti%2BLvHoyZfkO876gXACs%2B2TTFGifuAvAs3xkef%2Fs4NIkhXFYD8aPQC3LKKA9YWz0%2FqkDJOQl0%2B1GMPZw%3D%3D&ctl00%24ContentPlaceHolder1%24hideNeedValidateCode=True&mobilePhone=&emailAddress="+ this.txtU.Text.Trim() + "&userPassword=asdasd12bb3&rePassword=asdasd12bb3&verifyCode="
                    + this.txtCode.Text.Trim() + "&ctl00%24ContentPlaceHolder1%24reg_btnSubmit=%CF%C2%D2%BB%B2%BD%A3%AC%D1%E9%D6%A4&hidEmail="
                    + this.txtU.Text.Trim() + "&hidAction=0&hidPhone=&ctl00%24ContentPlaceHolder1%24hidEmailRetcode=2&ctl00%24ContentPlaceHolder1%24hidEmailValue="
                    + this.txtU.Text.Trim() + "&hidCode=&ctl00%24ContentPlaceHolder1%24hidCheckMobileRetcode=0&ctl00%24ContentPlaceHolder1%24hidMobilePhone=0&ctl00%24ContentPlaceHolder1%24hidVerifyCode=0&ctl00%24ContentPlaceHolder1%24hidImgCodeDatahash=k3Y4QkdW1491533255006";
byte[] btys = Encoding.UTF8.GetBytes(strPOST);

Stream stream = Req.GetRequestStream();
stream.Write(btys, 0, btys.Length);
stream.Flush();
Res = (HttpWebResponse)Req.GetResponse();
Stream responseStream = Res.GetResponseStream();

//将网页获取的流读成string
StreamReader sr = new StreamReader(responseStream, Encoding.GetEncoding("GB2312"));
string strResult = sr.ReadToEnd();
this.TXTmsg.Text = (strResult);

© 著作权归作者所有

共有 人打赏支持
D
粉丝 0
博文 18
码字总数 4127
作品 0
私信 提问

暂无文章

FinderWeb2.4.9 程序员的看日志利器

FinderWeb2.4.9 程序员的看日志利器

吴伟祥
1分钟前
0
0
PHP的pcntl进程控制教程一(pcntl_fork)

pcntl 简介 PHP的进程控制支持实现了Unix方式的进程创建, 程序执行, 信号处理以及进程的中断。 进程控制不能被应用在Web服务器环境,当其被用于Web服务环境时可能会带来意外的结果。 这份文档...

hansonwong
6分钟前
0
0
php扩展模块安装

11月21日任务 11.32 php扩展模块装安装 /usr/local/php/bin/php -m //查看模块 下面安装一个redis的模块 cd /usr/local/src/ wget https://codeload.github.com/phpredis/phpredis/zip/deve......

zgxlinux
7分钟前
0
0
windows下使用IDEA创建VUE项目

1.环境搭建 1.1检测是否安装好nodejs和npm 检测命令 node -v npm -v 如果没有安装需要先安装 nodejs的下载路径:https://nodejs.org/en/download/ 在Windows上安装时务必选择全部组件,包括勾...

文文1
14分钟前
1
0
Mybatis插件plugin应用测试,替换查询sql

1、新建插件 import org.apache.ibatis.executor.CachingExecutor;import org.apache.ibatis.executor.Executor;import org.apache.ibatis.executor.parameter.ParameterHandler;im......

jcc_codingBoy
19分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部