日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

自动登录DISCUZ,发帖的代码(部分)

發(fā)布時(shí)間:2025/5/22 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 自动登录DISCUZ,发帖的代码(部分) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

有點(diǎn)無(wú)聊的東西,不是通用的,不過(guò)RD提供了我們論壇用的discuz的hashform的計(jì)算代碼,也許通用的DISCUZ灌水機(jī)器人是我這種菜鳥也能搞出來(lái)的。
關(guān)于代碼,沒(méi)有什么技術(shù)含量,先用一個(gè)叫Ethereal的軟件抓到提交的值,然后用.NET中對(duì)應(yīng)的庫(kù)即可完成。下面是主要的類:

?

class?Robot
????
{
????????
/**////?attributes
????????//?cookies
????????private?CookieCollection?CkCollection?=?null;
????????
//?request?and?response
????????private?HttpWebRequest?SparkRequest?=?null;
????????
private?HttpWebResponse?SparkResponse?=?null;
????????
//?some?url
????????private?string?LoginUrl?=?null;
????????
private?string?ReplyUrl?=?null;

????????
//?constructer
????????public?Robot()
????????
{
????????????CkCollection?
=?new?CookieCollection();
????????}


????????
//?logining
????????public?string?Login(string?url,?string?usr,string?pass)
????????
{
????????????
string?Return?=?null;
????????????
this.LoginUrl?=?url;
????????????
//?may?be?I?should?add?a?functin?for?create?string
????????????string?loginstr?=?"formhash=3bd8bc0a&referer=index.php&loginmode=&styleid=&cookietime=2592000&loginfield=username&username="?+?usr;
????????????loginstr?
+=?"&password="?+?pass;
????????????loginstr?
+=?"&questionid=0&answer=&loginsubmit=提?交";
????????????loginstr?
=?EncodePost(loginstr);
????????????
byte[]?replybyte?=?Encoding.UTF8.GetBytes(loginstr);
????????????
????????????
try
????????????
{
????????????????CookieContainer?sparkc?
=?new?CookieContainer();
????????????????SparkRequest?
=?(HttpWebRequest)WebRequest.Create(url);
????????????????SparkRequest.CookieContainer?
=?sparkc;
????????????????SparkRequest.ContentType?
=?"application/x-www-form-urlencoded";
????????????????SparkRequest.Method?
=?"POST";

????????????????SparkRequest.ContentLength?
=?replybyte.Length;
????????????????Stream?newStream?
=?SparkRequest.GetRequestStream();
????????????????newStream.Write(replybyte,?
0,?replybyte.Length);
????????????????newStream.Close();

????????????????SparkResponse?
=?(HttpWebResponse)SparkRequest.GetResponse();
????????????????Stream?dataStream?
=?SparkResponse.GetResponseStream();
????????????????StreamReader?reader?
=?new?StreamReader(dataStream,?Encoding.GetEncoding("gb2312"));
????????????????Return?
=?reader.ReadToEnd();

????????????????
//?check?cookie
????????????????foreach?(Cookie?temp?in?SparkResponse.Cookies)
????????????????
{
????????????????????
if?(temp.Domain?!=?"spark.cjlu.edu.cn")
????????????????????????temp.Domain?
=?"spark.cjlu.edu.cn";
????????????????}


????????????????CkCollection?
=?SparkResponse.Cookies;
????????????}

????????????
catch
????????????
{
????????????????
return?null;
????????????}

????????????
return?Return;
????????}


????????
//?overload
????????/**//*
????????public?bool?Login(string?usr,?string?pass)
????????{
????????????;
????????}
*/


????????
//?reply……
????????public?string?Reply(string?url,string?formhash,string?title,string?content)
????????
{
????????????SparkRequest?
=?(HttpWebRequest)WebRequest.Create("http://spark.cjlu.edu.cn/bbs/"+url);
????????????SparkRequest.ContentType?
=?"application/x-www-form-urlencoded";
????????????SparkRequest.Method?
=?"POST";
????????????
//SparkRequest.Referer?=?"http://spark.cjlu.edu.cn/bbs/index.php";
????????????SparkRequest.KeepAlive?=?true;
????????????SparkRequest.AllowWriteStreamBuffering?
=?false;

????????????
//?set?cookie
????????????CookieContainer?cookieCon?=?new?CookieContainer();
????????????SparkRequest.CookieContainer?
=?cookieCon;
????????????SparkRequest.CookieContainer.Add(CkCollection);

????????????
//?get?post?value
????????????string?reply?=?EncodePost("formhash="?+?formhash?+?"&subject=&usesig=1&message="?+?content);
????????????
byte[]?replybyte?=?Encoding.UTF8.GetBytes(reply);
????????????SparkRequest.ContentLength?
=?replybyte.Length;
????????????Stream?newStream?
=?SparkRequest.GetRequestStream();
????????????newStream.Write(replybyte,?
0,?replybyte.Length);
????????????newStream.Close();

????????????
//?get?response
????????????SparkResponse?=?(HttpWebResponse)SparkRequest.GetResponse();
????????????Stream?dataStream?
=?SparkResponse.GetResponseStream();
????????????StreamReader?reader?
=?new?StreamReader(dataStream,?Encoding.GetEncoding("gb2312"));
????????????
string?tt?=?reader.ReadToEnd();

????????????reader.Close();
????????????dataStream.Close();
????????????SparkResponse.Close();

????????????
return?tt;
????????}


????????
//?encode?the?post?string
????????private?string?EncodePost(string?input)
????????
{
????????????
string?output?=?null;
????????????Char[]?reserved?
=?{?'?',?'=',?'&'?};
????????????
if?(input?!=?null)
????????????
{
????????????????
int?i?=?0,?j;
????????????????
while?(i?<?input.Length)
????????????????
{
????????????????????j?
=?input.IndexOfAny(reserved,?i);
????????????????????
if?(j?==?-1)
????????????????????
{
????????????????????????output?
=?output?+?HttpUtility.UrlEncode(input.Substring(i,?input.Length?-?i),?System.Text.Encoding.GetEncoding("gb2312"));
????????????????????????
break;
????????????????????}

????????????????????
string?tt?=?HttpUtility.UrlEncode(input.Substring(i,?j?-?i),?System.Text.Encoding.GetEncoding("gb2312"));
????????????????????output?
+=?tt;
????????????????????output?
+=?input.Substring(j,?1);
????????????????????i?
=?j?+?1;
????????????????}

????????????????
return?output;
????????????}

????????????
else
????????????????
return?null;
????????}

????}
?

轉(zhuǎn)載于:https://www.cnblogs.com/melorain/archive/2007/02/01/637345.html

總結(jié)

以上是生活随笔為你收集整理的自动登录DISCUZ,发帖的代码(部分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。