如何使用httpcode发起POST请求
HttpCode使用篇使用HttpCode时,请先引用 System.Web
Framework 4.0 时需要引用System.Web.Extensions
使用httpcode发起Post请求
方法一: 使用HttpHelpers类获取结果
string url = "bbs.msdn5.com";//请求地址
string res = string.Empty;//请求结果,请求类型不是图片时有效
string pdata = "post时所需要的数据";//提交数据(必须项)
System.Net.CookieContainer cc = new System.Net.CookieContainer();//自动处理Cookie对象
HttpHelpers helper = new HttpHelpers();//发起请求对象
HttpItems items = new HttpItems();//请求设置对象
HttpResults hr = new HttpResults();//请求结果
items.URL = url;//请求的url地址
items.Referer = "referer如果有请携带"; //referer头,如果需要请填写
items.Container = cc;//自动处理Cookie时,每次提交时对cc赋值即可
items.Postdata = pdata;//提交的数据
items.Method = "Post";//设置提交方式为post方式提交(默认为Get方式提交)
hr = helper.GetHtml(items);//发起请求并获得结果
res = hr.Html;//得到请求结果
方法二: 使用Wininet类获取结果
string url = "bbs.msdn5.com";//请求地址
string res = string.Empty;//请求结果,请求类型不是图片时有效
string pdata = "post提交的数据";//提交数据(必须项)
res =wnet.PostUtf8(url, pdata); //使用UTF8编码提交
//res = wnet.PostData(url, pdata); 使用gbk编码提交
方法三: 使用XJHTTP类获取结果
XJHTTP xjhttp = new XJHTTP();
CookieContainer cc = new CookieContainer();//自动处理cookie
string referer = "www.msdn5.com"; //referer头数据,如果没有请留空
string postdata = "这里是提交的数据"; //post提交数据
HttpResults hr = xjhttp.PostHtml(PostUrl, referer, postdata, false, cc);
参数说明:
xjhttp.PostHtml("提交的url", "Referer数据头","提交的数据", "Ajax标志不需要时请填写false", "自动处理Cookie对象");
三种方式说明
方法一;比较灵活;(推荐使用)
方法二则是与IE一样,使用底层API;
方法三则是提供懒人方法
有点思路。。见解到了 刚开始学习这方面的知识,请问"提交的数据"是怎么得到的?是什么格式的? 请问得到cookie以后,我想对登陆后的网页继续进行其他的操作该怎么办?这个cookie怎么用!是要在登录成功后的每个网页上进行get或者post操作吗? njjwdy 发表于 2016-5-10 08:37
请问得到cookie以后,我想对登陆后的网页继续进行其他的操作该怎么办?这个cookie怎么用!是要在登录成功后 ...
带上那个cookie啊.
有免费课啊.
http://bbs.msdn5.com/forum.php?mod=forumdisplay&fid=2&filter=typeid&typeid=16 请问"提交的数据"是怎么得到的?是什么格式的? self001 发表于 2016-9-18 11:07
请问"提交的数据"是怎么得到的?是什么格式的?
免费课程详解 http
http://bbs.msdn5.com/forum.php?m ... ypeid&typeid=16 跟着示范练一练。
页:
[1]