Code segment:
Const loginurl = 'http://www.9cbs.net/member/logon.asp'; posturl = 'http://community.9cbs.net/expert/postnew_sql.asp'; replyURL = 'http: // community. 9cbs.net/expert/reply.asp '; msgurl =' http://community.9cbs.net/Message_Board/postsend.asp ';
MyCookList: Global variable, get the current user's cookieidHttp1: TidHTTP;
Login: function Logon (UserName, PassWord, CookieTime: string): boolean; var LoginInfo: TStrings; Response: TStringStream; i: Integer; Cookie: string; begin Result: = False; Cookie: = ''; MyCookList: = '' ; Response: = TStringStream.Create ( ''); LoginInfo: = TStringList.Create; try LoginInfo.Clear; LoginInfo.Add ( 'login_name =' UserName); LoginInfo.Add ( 'password =' passWord); LoginInfo. Add ('from = http:///community.9cbs.net/expert/forum.asp'); logininfo.add ('cookietime =' cookietime); logininfo.add ('x = 0'); logininfo.add 'y = 0'); IDHTTP1.Request.referer: = 'http://www.9cbs.net/member/logon.asp'; IDHTTP1.REQUEST.FROM: = 'http: //community.9cbs.net/ Expert / forum.asp '; try idhttp1.post (loginull, logininfo, response); Except ShowMessage; end; showMessage (response.DataString); // Find out the cookie for i from the return page: = 0 to IDHTTP1.RESPONSE.RAWHEADERS.COUNT-1 Do Begin if Uppercase (Copy (Idhttp1.Response.Rawheade) RS [I], 1, 10)) = 'set-cookie' Then Begin cookie: = trim (Idhttp1.Response.Rawheaders [i], 12, maxint)); cookie: = Copy (cookie, 1, POS ( ';', Cookie)); MyCookList: = MyCookList Cookie; // showmessage (Cookie); end; end; IdHTTP1.Request.RawHeaders.Add ( 'Cookie:' MyCookList); finally LoginInfo.Free; Response. Free; end; if longth (mycooklist)> 200 the result: = true;
// reply function Reply (TopicID, Content: string): boolean; var ReplyInfo: TStrings; Response: TStringStream; begin Result: = False; ReplyInfo: = TStringList.Create; Response: = TStringStream.Create ( ''); try begin // Remove the replyinfo.clear; replyInfo.add ('Topicid =' Topici); replyInfo.add ('xmlreply = aaaaa'); replyInfo.add ('9cbsname ='); replyInfo.add ('9cspassword =' ); ReplyInfo.add ('replycontent =' content); idHttp1.Request.customHeaders.add ('cookie:' copy (mycooklist, 1, length (mycooklist) -1)); idHttp1.Request.referer: = ' http://community.9cbs.net/Expert/xsl/Reply_Xml.asp Topicid = ' TopicID; IdHTTP1.Request.UserAgent: =' redhat / 9.0 '; try IdHTTP1.Post (ReplyUrl, ReplyInfo, Response); except showmessage ('Reply Failed'); EXIT; END; // ShowMessage (Response.DataString); if POS ('Add completion, generating a static page, please wait a', response.DataString> 0 Then Result: = true; end Finally replyinfo.free; response.free; end; end;
// posts function PostNew (RoomID, Point, TopicName, Content: string): boolean; var PostInfo: TStrings; Response: TStringStream; begin Result: = False; PostInfo: = TStringList.Create; Response: = TStringStream.Create ( ' '); Try begin // Number Page // TypeState = 1 & Point = 20 & TopicName = TEST & ROOM = 1404 & Content = 111222 PostInfo.clear; PostInfo.add (' TypeState = 1 '); PostInfo.add (' Point = ' POINT) Postinfo.add ('TopicName =' TopicName); PostInfo.add ('Room =' Roomid); Postinfo.add ('Content =' Content); IDHTTP1.Request.customHeaders.Add ('cookie:' copy (MyCookList, 1, length (MyCookList) -1)); IdHTTP1.Request.CacheControl: = 'no-cache'; IdHTTP1.Request.UserAgent: = 'Windows Advanced Server / 5.0'; try IdHTTP1.Post (postUrl, PostInfo, Response); Except ShowMessage ('Posting Failed'); EXIT; End; // ShowMessage (Response.DataString); if POS ('Add success, please wait, generating static page', response.DataString> 0 THEN Result: = true; end; finally postinfo.free ..................