您现在的位置是:首页 > cms教程 > Discuz教程Discuz教程

自动登录DISCUZ发帖的实现方法示例

怀蕊2025-06-27Discuz教程已有人查阅

导读有点无聊的东西,不是通用的,不过RD提供了我们论坛用的discuz的hashform的计算代码,也许通用的DISCUZ灌水机器人是我这种菜鸟也能搞出来的。

有点无聊的东西,不是通用的,不过RD提供了我们论坛用的discuz的hashform的计算代码,也许通用的DISCUZ灌水机器人是我这种菜鸟也能搞出来的。
关于代码,没有什么技术含量,先用一个叫Ethereal的软件抓到提交的值,然后用.NET中对应的库即可完成。下面是主要的类:
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- -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(");
SparkRequest.ContentType = "application/x- -form-urlencoded";
SparkRequest.Method = "POST";
//SparkRequest.Referer = "";
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;
}
}

本文标签:

很赞哦! ()

相关源码

  • (自适应)pbootcms家政服务保洁保姆打扫卫生网站模板下载本模板基于PbootCMS内核开发,为家政服务企业量身定制。设计风格温馨亲切,突出家政行业的专业与贴心服务特性,多方位展示企业服务项目与优势。查看源码
  • (自适应响应式)黑色LED显示屏户外广告屏网站源码下载这是一款基于PbootCMS内核开发的响应式网站模板,专门为LED显示屏及户外广告行业打造。模板适配各类显示设备,帮助企业快速搭建专业官网,展示产品与服务优势,有效提升品牌形象。查看源码
  • (响应式)蓝色智能摄像头安防防盗电子设备免费pbootcms源码下载这是一款针对智能安防行业特点设计的网站模板,采用蓝色系配色方案,体现科技感和安全性。模板包含产品展示、解决方案、技术支持和新闻中心等核心模块,能够全面展示智能安防设备的技术特点和行业应用。查看源码
  • (自适应)帝国CMS7.5模板淘宝客导购博客文章源码本模板基于帝国CMS7.5内核深度开发,为电商导购类网站设计。采用响应式布局技术,确保在手机、平板及电脑端均能获得优质浏览体验。模板内置商品推荐模块与优惠信息展示区,可快速搭建专业导购平台。查看源码
  • WordPress主题模板主题巴巴/博客X主题源码免费下载博客X主题专注于内容创作领域,为博客、资讯类网站提供专业的内容展示解决方案。该模板采用精心设计的布局结构,能够有效提升内容的可读性和用户停留时间。查看源码
  • (自适应)蓄电池能源智能数码科技产品pbootcms模板源码下载本款基于PbootCMS开发的网站模板为蓄电池及能源科技企业设计,特别适合锂电池、储能系统、新能源电池等产品的展示与推广。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐