Posting to a forum programmatically using Delphi

I’m a member of a web site where we run various games in the forums and for several that can be tedious to keep track of manually I’ve written some code in Borland Delphi to automate the task. The forum itself is phpBB and I use the web browser component included with Delphi to edit posts directly in the forum. Being able to post to a website as though a user submitted a form is handy for these sorts to tasks where you don’t have access to the underlying forum database. I’ve posted the more interesting parts of the code that format the request and setup the correct headers:

  strData: String;
  PostData, Headers: OleVariant;
strData := 'message=' + HTTPEncode(MessageData) + '&notify=on&mode=editpost&p=' + IntToStr(PostID) + '&post=+Post+';

PostData := VarArrayCreate([0, Length(strData) - 1], varByte);

for i := 1 to Length(strData) do
  PostData[i-1] := Ord(strData[i]);

Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;

WebBrowser.Navigate('' + MainTopicID.Text, EmptyParam, EmptyParam, PostData, Headers);

Leave a Reply

Your email address will not be published. Required fields are marked *