最近在做一个发贴工具,用的是delphi2010 indy10 ,论坛是discuz big5码,登陆没问题,但是发贴时,贴子内容是乱码。
发贴函数如下:Function TForm1.postinfo(url, subject, wsmessage,fid: string): Boolean;
var
Param:TStringList;
geturl:String;
   Response:TStringStream;
begin
Result:=False;
geturl:=url+'/index.php';
//idhttp1.AllowCookies:=True;
idhttp1.HandleRedirects:=True;
//idhttp1.Request.Accept:='image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*';
    idhttp1.Request.Referer:=url+'/post.php?action=newthread&fid='+fid;
    IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoKeepOrigProtocol];
idhttp1.Request.AcceptLanguage:='zh-cn';
idhttp1.Request.ContentType:='application/x-www-form-urlencoded' ;
idhttp1.Request.AcceptEncoding :='gzip, deflate';
idhttp1.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 2.0.50727)';
 idhttp1.Request.Connection:='keep-alive';  idhttp1.Request.CacheControl:='no-cache';
Param:=TStringList.Create;
Response:=TStringStream.Create('');
try
wsmessage:=ansitoutf8(wsmessage);
param.Clear;
Param.Add('formhash='+formhash);
param.Add('wysiwyg=0');
Param.Add('subject='+subject);
Param.Add('message='+wsmessage);
param.Add('iconid=');
param.Add('addfeed=1');
param.Add('topicsubmit=%B5o%B7s%B8%DC%C3D');
//Param.Add('userlogin=%E7%99%BB%E5%BD%95');
url:=url+'/post.php?action=newthread&fid='+fid+'&extra=&topicsubmit=yes';
try
   idhttp1.Post(url,param,response);    
    
    except
    showmessage('发贴失败');
    end;
finally
    Param.Free;
   response.Free;
end;
  showmessage(response.DataString);end;