模拟Post/get提交数据 并抓取返回数据
来源:互联网 发布:英文软件汉化 编辑:程序博客网 时间:2024/05/16 11:40
最近需要做的项目中,使用httpwebrequest httpwebrespone来模拟提交数据
还有模拟用户登录后提交数据。
下面做个简单一点的。模拟post提交数据,get在前面的抓取sina的天气预报也使用到了。
下面是代码
//提交的post数据
string postData = string.Format("account={0}&reaccount={0}&cardcode={1}&cardpassword={2}",txtLoginId.Text,txtCardNo.Text,txtPass.Text);postData += string.Format("&__EVENTTARGET={0}&__EVENTARGUMENT=&__VIEWSTATE={1}", "nextStep", "YToxOntzOjExOiJjdXJyZW50VXNlciI7YjowO30=");
HttpWebResponse response;
HttpWebRequest request;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
request = (HttpWebRequest)WebRequest.Create("url");
data = encoding.GetBytes(postData);
request.Method = "POST";
request.ProtocolVersion = HttpVersion.Version10;
request.UserAgent = "Mozilla/4.0";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
string html = string.Empty;
try
{
//获取服务器返回的资源
response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
html = reader.ReadToEnd();
reader.Close();
response.Close();
textBox1.Text = html;
}
catch (Exception ex)
{
label4.Text = ex.Message;
}
- 模拟Post/get提交数据 并抓取返回数据
- 模拟Post/get提交数据 并抓取返回数据
- PHP模拟GET和POST提交数据
- socket模拟http中post或者get提交数据,并获得响应数据
- socket模拟http中post或者get提交数据,并获得响应数据
- php模拟提交并取得返回数据
- fiddler使用教程2--数据post、get模拟提交数据
- PHP模拟POST提交数据并获得返回值之CURL方法
- PHP利用CURL方法模拟POST提交数据并获得返回值的小细节
- 使用RESTClient插件进行数据模拟(GET,POST)提交
- 如何使用Fiddler2模拟POST和Get提交数据
- CURL模拟post,get提交数据-实际应用
- httpClient4.3 模拟Post提交,模拟Post上传文件并解决服务端使用spingMVC时upload.parseRequest(request)解析不到File,Pos简单抓取页面数据
- CHttpFile GET/POST 提交数据
- GET和POST提交数据
- C# POST,GET 提交数据
- php get/post 提交数据
- Java发送http POST,GET,并获取返回数据
- Android系统名词解释汇总
- std::min std::max
- MPEG-4/H.264视频编解码工程实践(二)
- 全局的callback函数访问一个类的成员变量
- AJAX程序设计
- 模拟Post/get提交数据 并抓取返回数据
- qt 中文编码
- 面试题 引用和指针
- CentOS 防火墙配置 80端口
- Q & A (1)
- 编写和提交自己的第一个内核patch
- 一、Qt Creator的安装和hello world程序的编写
- Shell脚本调试技术
- 矩阵求导