J
JackyKen
Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个自动回复Discuz!论坛贴子的程序,用的IdHTTP(WinXP+Delphi7),登录完全正确,但回贴时总提示:“您的请求来路不正确或验证字串不符,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。”
我就用的WinXP自带的防火墙,没有装任何第三方防火墙,用于测试的论坛回贴也不需要验证码,请问这是什么问题,该怎么解决。请各位指点,多谢!
附登录及回贴的代码如下:
BaseUrl='http://www.55188.com/';
ReplyUrl=BaseUrl+'post.php?action=reply&fid=20&tid=1902786&extra=page%3D1';
LoginUrl=BaseUrl+'logging.php?action=login';
MyCookList:string; //为全局变量
function Logon(UserName, PassWord, CookieTime: string): boolean;
var
LoginInfo: TStrings;
Response: TStringStream;
i: Integer;
Cookie,strTmp:string;
begin
Result :=False;
Cookie:='';
MyCookList :='';
Response := TStringStream.Create('');
LoginInfo := TStringList.Create;
try
LoginInfo.Clear;
LoginInfo.Add('loginfield=username');
LoginInfo.Add('username='+UserName);
LoginInfo.Add('password='+PassWord);
LoginInfo.Add('questionid=0');
LoginInfo.Add('cookietime=315360000');
LoginInfo.Add('loginsubmit=yes');
try
IdHTTP1.Post(LoginUrl,LoginInfo,Response);
except
showmessage('登陆失败');
Exit;
end;
//从返回的页面中找出cookie
for i :=0 to IdHTTP1.Response.RawHeaders.Count-1 do
begin
strTmp:=IdHTTP1.Response.RawHeaders;
if UpperCase(Copy(strTmp,1,10)) = 'SET-COOKIE' then
begin
Cookie :=Trim(Copy(strTmp,12,MAXINT));
Cookie :=Copy(Cookie,1,Pos(';',Cookie));
MyCookList :=MyCookList+Cookie;
end;
end;
IdHTTP1.Request.RawHeaders.Add('Cookie: '+MyCookList);
finally
LoginInfo.Free;
Response.Free;
end;
result:=True;
end;
function Reply(TopicID, Content: string): boolean;
var
ReplyInfo: TStrings;
Response: TStringStream;
begin
Result :=False;
ReplyInfo := TStringList.Create;
Response :=TStringStream.Create('');
try
begin
ReplyInfo.Clear;
ReplyInfo.Add('subject='+TopicID);
ReplyInfo.Add('message='+Content);
ReplyInfo.Add('replysubmit=yes');
IdHTTP1.Request.CustomHeaders.Add('Cookie: '+copy(MyCookList,1,length(MyCookList)-1));
try
IdHTTP1.Post(ReplyUrl,ReplyInfo,Response);
except
showmessage('回复失败');
exit;
end;
if pos('添加完成,正在生成静态页面,请稍候',Response.DataString)>0 then
Result :=true;
end;
finally
ReplyInfo.Free;
Response.Free;
end;
end;
我就用的WinXP自带的防火墙,没有装任何第三方防火墙,用于测试的论坛回贴也不需要验证码,请问这是什么问题,该怎么解决。请各位指点,多谢!
附登录及回贴的代码如下:
BaseUrl='http://www.55188.com/';
ReplyUrl=BaseUrl+'post.php?action=reply&fid=20&tid=1902786&extra=page%3D1';
LoginUrl=BaseUrl+'logging.php?action=login';
MyCookList:string; //为全局变量
function Logon(UserName, PassWord, CookieTime: string): boolean;
var
LoginInfo: TStrings;
Response: TStringStream;
i: Integer;
Cookie,strTmp:string;
begin
Result :=False;
Cookie:='';
MyCookList :='';
Response := TStringStream.Create('');
LoginInfo := TStringList.Create;
try
LoginInfo.Clear;
LoginInfo.Add('loginfield=username');
LoginInfo.Add('username='+UserName);
LoginInfo.Add('password='+PassWord);
LoginInfo.Add('questionid=0');
LoginInfo.Add('cookietime=315360000');
LoginInfo.Add('loginsubmit=yes');
try
IdHTTP1.Post(LoginUrl,LoginInfo,Response);
except
showmessage('登陆失败');
Exit;
end;
//从返回的页面中找出cookie
for i :=0 to IdHTTP1.Response.RawHeaders.Count-1 do
begin
strTmp:=IdHTTP1.Response.RawHeaders;
if UpperCase(Copy(strTmp,1,10)) = 'SET-COOKIE' then
begin
Cookie :=Trim(Copy(strTmp,12,MAXINT));
Cookie :=Copy(Cookie,1,Pos(';',Cookie));
MyCookList :=MyCookList+Cookie;
end;
end;
IdHTTP1.Request.RawHeaders.Add('Cookie: '+MyCookList);
finally
LoginInfo.Free;
Response.Free;
end;
result:=True;
end;
function Reply(TopicID, Content: string): boolean;
var
ReplyInfo: TStrings;
Response: TStringStream;
begin
Result :=False;
ReplyInfo := TStringList.Create;
Response :=TStringStream.Create('');
try
begin
ReplyInfo.Clear;
ReplyInfo.Add('subject='+TopicID);
ReplyInfo.Add('message='+Content);
ReplyInfo.Add('replysubmit=yes');
IdHTTP1.Request.CustomHeaders.Add('Cookie: '+copy(MyCookList,1,length(MyCookList)-1));
try
IdHTTP1.Post(ReplyUrl,ReplyInfo,Response);
except
showmessage('回复失败');
exit;
end;
if pos('添加完成,正在生成静态页面,请稍候',Response.DataString)>0 then
Result :=true;
end;
finally
ReplyInfo.Free;
Response.Free;
end;
end;