{ TSendmailThread }
constructor TPostMsgThread.Create(ContentType:string;UserName:string;PassWord:string;PostUrl:string;PostBody:string);
begin
{code here}
FContentType:=ContentType;
FUserName:=UserName;
FPassWord:=PassWord;
FPostUrl:=PostUrl;
FPostBody:=PostBody;
FHTTPBody:='''';
FPostState:=-1;
HTTP:=TIdHTTP.Create(nil) ;
HTTP.Port:=80;
HTTP.ProtocolVersion:=pv1_0;
HTTP.RecvBufferSize:=1024;
HTTP.RedirectMaximum:=15;
HTTP.HandleRedirects:=true;
inherited Create(False);
end;
destructor TPostMsgThread.Destroy;
begin
{code here}
HTTP.Free;
inherited Destroy;
end;
procedure TPostMsgThread.Execute;
begin
FreeOnTerminate:=true;
try
if FContentType=''Get'' then FHTTPBody:=GetMsg(FUserName,FPassWord,FPostUrl)
else FPostState:=postmsg(FContentType,FUserName,FPassWord,FPostUrl,FPostBody)
except
FPostState:=-11;
end;
end;
function TPostMsgThread.GetMsg(UserName:string;PassWord:string;PostUrl:string):String;
begin
try
// Set the properties for HTTP
HTTP.Request.Username := UserName;
HTTP.Request.Password := PassWord;
//HTTP.Request.ProxyServer := '''';
//HTTP.Request.ProxyPort := StrToIntDef('''', 80);
//HTTP.Request.ContentType := ContentType;
result:=HTTP.Get(PostUrl);
except
result:='''';
end;
end;
function TPostMsgThread.postmsg(ContentType:string;UserName:string;PassWord:string;PostUrl:string;PostBody:string):integer;
var
Response: TStringStream;
stra:TStrings;
begin
try
// Set the properties for HTTP
HTTP.Request.Username := UserName;
HTTP.Request.Password := PassWord;
//HTTP.Request.ProxyServer := '''';
//HTTP.Request.ProxyPort := StrToIntDef('''', 80);
HTTP.Request.ContentType := ContentType;
http.Request.Referer:=PostUrl;
// post bbs msg
Response := TStringStream.Create('''');
try
stra:=TStringList.Create;
try
stra.Text:=PostBody;
HTTP.Post(PostUrl, stra, Response);
finally
stra.Free;
end;
finally
Response.Free;
end;
result:=HTTP.ResponseCode;
except
result:=HTTP.ResponseCode;
end;
end;
//==========================================================