文档章节

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
私信 提问

暂无文章

求推广,德邦快递坑人!!!!

完全没想好怎么来吐槽自己这次苦逼的德邦物流过程了,只好来记一个流水账。 从寄快递开始: 2019年1月15日从 德邦物流 微信小app上下单,截图如下: 可笑的是什么,我预约的是17号上门收件,...

o0无忧亦无怖
28分钟前
1
0
Mac Vim配置

1.升级 vim   我自己 MacBook Pro 的系统还是 10.11 ,其自带的 vim 版本为 7.3 ,我们将其升至最新版: 使用 homebrew : brew install vim --with-lua --with-override-system-vim 这将下...

Pasenger
40分钟前
0
0
vmware安装Ubuntu上不了网?上网了安装不了net-tools,无法执行ifconfig?

1.重新设置网络适配器还是不行,如下指定nat 2.还需要指定共享网络,我是在无线环境下 3.无法执行ifconfig https://packages.ubuntu.com/bionic/net-tools到这个网站下载net-tools的deb文件...

noob_chr
今天
1
0
解决SVN:E210007无法协商认证机制

svn:E210007 svn: Cannot negotiate authentication mechanism 执行下面代码即可 sudo yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-ldap...

临江仙卜算子
今天
1
0
java8的时间和`Date`的对比

java8的时间和Date的对比 java8提供了新的时间接口。相对Date,Calendar,个人感觉最大的好处是对时间操作的学习成本很低,比Calendar低。 1. LocalDate,LocalTime,LocalDateTime LocalDate 代...

北风刮的不认真了
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部