文档章节

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

暂无文章

你为什么在Redis里读到了本应过期的数据

一个事故的故事 晚上睡的正香突然被电话吵醒,对面是开发焦急的声音:我们的程序在访问redis的时候读到了本应过期的key导致整个业务逻辑出了问题,需要马上解决。 看到这里你可能会想:这是不...

IT--小哥
47分钟前
0
0
祝大家节日快乐,阖家幸福! centos GnuTLS 漏洞

yum update -y gnutls 修复了GnuTLS 漏洞。更新到最新 gnutls.x86_64 0:2.12.23-22.el6 版本

yizhichao
昨天
3
0
Scrapy 1.5.0之选择器

构造选择器 Scrapy选择器是通过文本(Text)或 TextResponse 对象构造的 Selector 类的实例。 它根据输入类型自动选择最佳的解析规则(XML vs HTML): >>> from scrapy.selector import Sele...

Eappo_Geng
昨天
2
0
Windows下Git多账号配置,同一电脑多个ssh-key的管理

Windows下Git多账号配置,同一电脑多个ssh-key的管理   这一篇文章是对上一篇文章《Git-TortoiseGit完整配置流程》的拓展,所以需要对上一篇文章有所了解,当然直接往下看也可以,其中也有...

morpheusWB
昨天
3
0
中秋快乐!!!

HiBlock
昨天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部