|
楼主 |
发表于 2014-6-17 16:55:21
|
显示全部楼层
本帖最后由 YoYo-You 于 2014-6-17 17:05 编辑
还有就是源码问题,只要照HttpHelp上面的获取Cookie方法不就可以获取了吗.这里需要注意的是比如有些是ajax Cookie一定要要是string类型,不要加 ResultCookieType = ResultCookieType.CookieCollection,这个,会让返回不了Cookie的值,反正就一句话如果CookieCollection获取不了就用Cookie,还有就是有些页面是301的要跳转的,你要几次才能有真正的Cookie下面是我刚搞的小米竞猜足球的代码.
//竞猜足球代码
private void PlayBoxThread()
{
if (rboBox1.Checked || rboBox2.Checked)
{
int a = rboBox1.Checked ? 1 : 3;
int i = 0;
foreach (string key in dic.Keys)
{
if (dic[key] == null || dic[key].Equals("")) //dic[key]里面放的是登入后的Cookie这个论坛很多人又发了这样的代码如果登入Cookie的代码的
{
ajaxcookies.Add("");
continue;
}
string CookiesSrt = getCookieString(dic[key]);
HttpItem BoxItem = new HttpItem()
{
ResultCookieType = ResultCookieType.CookieCollection,
URL = "http://i.huodong.mi.com/guessworldcup/default/getcurguess?jsonpcallback=?",
Method = "GET",
Host = "i.huodong.mi.com",
Cookie = CookiesSrt
};
HttpHelper Box_helper = new HttpHelper();
HttpResult Box_resultes = Box_helper.GetHtml(BoxItem);
CookiesSrt += getCookieString(Box_resultes.CookieCollection);
string boxjson = Regex.Match(Box_resultes.Html.Trim(), "(?<=.\\().*\\)").ToString().Replace(")", "");
BoxInfo boxobj = JsonConvert.DeserializeObject<BoxInfo>(boxjson);
ajaxcookies.Add(CookiesSrt);
if (boxobj.code == 1)
{
HttpItem UserItem = new HttpItem()
{
URL = "http://i.huodong.mi.com/guessworldcup/default/getuserinfo?jsonpcallback=?",
Method = "GET",
Host = "i.huodong.mi.com",
Cookie = CookiesSrt,
};
HttpHelper User_helper = new HttpHelper();
HttpResult User_resultes = User_helper.GetHtml(UserItem);
boxjson = Regex.Match(User_resultes.Html.Trim(), "(?<=.\\().*\\)").ToString().Replace(")", "");
Boxinfo2 boxobj1 = JsonConvert.DeserializeObject<Boxinfo2>(boxjson);
if (boxobj.code == 1)
{
HttpItem submitboxitem = new HttpItem()
{
URL = string.Format("http://i.huodong.mi.com/guessworldcup/default/vote/?cid={0}&type={1}&v=1&jsonpcallback=setbox", boxobj.info.cid, a),
Method = "GET",
Cookie = CookiesSrt,
Host = "i.huodong.mi.com",
ContentType = "text/html; charset=utf-8"
};
Box_helper = new HttpHelper();
Box_resultes = Box_helper.GetHtml(submitboxitem);
boxjson = Regex.Match(Box_resultes.Html.Trim(), "(?<=setbox\\().*\\)").ToString().Replace(")", "");
BoxAnswer BoxAnswer = JsonConvert.DeserializeObject<BoxAnswer>(boxjson);
Other_Method DMSGD = new Other_Method(showListBoxText);
this.BeginInvoke(DMSGD, new object[] { 3, BoxAnswer.info, i });
i++;
}
}
Thread.Sleep(IControl.THREADSELLP);
}
}
}
//砸蛋的代码
private void ZaCaiDan()
{
int i = 0;
foreach (string c in ajaxcookies)
{
//C也是cookie这里需要注意到的是一定要完成上面的"http://i.huodong.mi.com/guessworldcup/default/getcurguess?jsonpcallback=?这个会返回一个Cookie这个Cookie是一个权限Id
if ( c.Equals(""))
{
continue;
}
HttpItem BoxItem = new HttpItem()
{
URL = "http://i.huodong.mi.com/guessworldcup/default/getxiaomiprize?m=0&jsonpcallback=getdan",
Method = "GET",
Host = "i.huodong.mi.com",
Cookie = c
};
HttpHelper Box_helper = new HttpHelper();
HttpResult Box_resultes = Box_helper.GetHtml(BoxItem);
string boxjson = Regex.Match(Box_resultes.Html.Trim(), "(?<=getdan\\().*\\)").ToString().Replace(")", "");
CaiDan boxobj = JsonConvert.DeserializeObject<CaiDan>(boxjson);
Other_Method DMSGD = new Other_Method(showListBoxText);
if (boxobj.code == 1 && (boxobj.data == 0 || boxobj.data == 1 || boxobj.data == 2 || boxobj.data == 3 || boxobj.data == 4 || boxobj.data == 5 || boxobj.data == 6))
{
this.BeginInvoke(DMSGD, new object[] { 3, boxobj.info, i });
}
else {
this.BeginInvoke(DMSGD, new object[] { 3, boxobj.info, i });
}
i++;
Thread.Sleep(IControl.THREADSELLP);
}
}
|
|