unit DwTh; interface uses Classes, u_op_seae_DsWebService, Sysutils, ActiveX,IdHTTP; type DwThread = class(TThread) idhttp1: TIdHTTP; private MBLNO,EVENT,STATE,response:WideString; _result:string; Param:TStringList; protected procedure Execute; override; procedure Giveanswer; procedure ThFail; procedure SetState(response: string); function DoPost(_URL:string;_Referer:string;_order:TStringList):WideString; public // constructor Create(_s: string;AWS:YzxfDelegatorPortType); virtual; constructor Create(_MBLNO: string); virtual; end; implementation uses U_op_seae,my_sys_function; var Rev: string; // aa:YzxfDelegatorPortType; URL: string; constructor DwThread.Create(_MBLNO: string); begin inherited Create(True); FreeOnTerminate := true; MBLNO:= _MBLNO; EVENT:=''; STATE:=''; Param:=TStringList.Create; _result:=''; IdHTTP1:=TIdHttp.Create; end; procedure DwThread.SetState(response: string); var _eventstart,_eventend,_statestart,_stateend:integer; _temp:string; begin _eventstart:=pos('name="__VIEWSTATE" id="',response); _temp:=copy(response,_eventstart+43,3000); _eventend:=pos('" />',_temp); _temp:=copy(_temp,0,_eventend-1); STATE:=_temp; _statestart:=pos('id="__EVENTVALIDATION" value="',response); _temp:=copy(response,_statestart+30,3000); _stateend:=pos('" />',_temp); _temp:=copy(_temp,0,_stateend-1); EVENT:=_temp; end; function DwThread.DoPost(_URL:string;_Referer:string;_order:TStringList):wideString; var Param:TStringList; RStream:TStringStream; post:AnsiString; begin Param:=TStringList.Create; RStream:=TStringStream.Create(''); Param:=_order; IdHTTP1.ProtocolVersion:=pv1_1; IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoTreat302Like303]; IdHTTP1.Request.Accept:='text/html, application/xhtml+xml, */*'; IdHTTP1.Request.UserAgent:='Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'; IdHTTP1.Request.AcceptEncoding:='gzip, deflate'; IdHTTP1.Request.Host:='56.qdcdc.com'; IdHTTP1.Request.ContentType:='application/x-www-form-urlencoded'; idhttp1.HandleRedirects:=true; IdHTTP1.Request.Referer:=_Referer; try IdHTTP1.Post(_URL,Param,RStream); except on e:Exception do//抛出所有异常 begin //doing something raise; end; end; result:=UTF8Decode(RStream.DataString); end; procedure DwThread.Execute; var AA_s, _t: string; revcount: integer; aa: DsWebServiceSoap; RStream:TStringStream; _getanswer: boolean; begin _getanswer := false; try response:=DoPost('http://cdp.qdcdc.com/CDP/login.aspx','',Param) ; SetState(response); //////////////////////// //输入帐号密码 点击登陆 RStream:=TStringStream.Create(''); Param.Clear; Param.Add('__VIEWSTATE='+state ); Param.Add('__EVENTVALIDATION=' + EVENT); Param.Add('user_name=user1'); Param.Add('password=88888888');// Param.Add('hdSuccess=true'); response:=DoPost('http://cdp.qdcdc.com/CDP/Login.aspx','http://cdp.qdcdc.com/CDP/Login.aspx',Param); SetState(response); //////////////////// //点击查询页面 Param.Clear; response:=DoPost('http://cdp.qdcdc.com/CDP/MftQuery/BillExportQuery.aspx','',Param) ; SetState(response); ///////////////////// Param.Clear; Param.Add('__VIEWSTATE='+state ); Param.Add('__EVENTVALIDATION=' + EVENT); Param.Add('txtIMO=' ); Param.Add('txtTransportName=' ); Param.Add('txtVoyageNo=' ); Param.Add('txtBillNo='+MBLNO ); Param.Add('LinkButtonQuery=%E6%9F%A5%E8%AF%A2' ); Param.Add('hdSelectRow=' ); Param.Add('hdData=' ); Param.Add('hdCols=%E5%BA%8F%E5%8F%B7%2C%E5%87%BA%E5%8F%A3%E6%8F%90%E5%8D%95%E5%8F%B7%2C%E9%A2%84%E9%85%8D%E8%88%B1%E5%8D%95%2C%E5%87%BA%E5%8F%A3%E8%BF%90%E6%8A%B5%E6%8A'); Param[Param.Count-1]:=Param[Param.Count-1]+'%A5%E5%91%8A%2C%E5%87%BA%E5%8F%A3%E8%A3%85%E8%BD%BD%2C%E5%87%BA%E5%8F%A3%E7%90%86%E8%B4%A7%2C%E5%87%BA%E5%8F%A3%E6%8A%A5%E5%85%B3%E7%8A%B6%E6%80%81%2C%E7%A9%BA%E7%AE%B1%E9%AA%8C%E6%94%BE%2C%E6%8F%90%E5%8D%95%E6%94%BE%E8%A1%8C'; Param.Add('hdChildHide=' ); Param.Add('hdColsHide=' ); Param.Add('hdColSpan=%E6%8F%90%E5%8D%95%E5%8F%B7' ); Param.Add('hdMutiQuery=' ); Param.Add('hdReturnResult=' ); Param.Add('hdLoadMarkText=' ); Param.Add('hdArrivalMarkText=' ); Param.Add('hdEmptyResult=' ); Param.Add('hdTalMarkText=' ); response:=DoPost('http://cdp.qdcdc.com/CDP/MftQuery/BillExportQuery.aspx' ,'http://cdp.qdcdc.com/CDP/MftQuery/BillExportQuery.aspx',Param); idhttp1.Disconnect; _result:=response; if (_result<>'') then begin synchronize(Giveanswer); _getanswer := true; end; finally if not _getanswer then begin Sleep(1500); synchronize(ThFail); end; end; // assignlogtofile('Send to WS False'); end; procedure DwThread.Giveanswer; var _s, _t: string; _i: integer; begin // Ycc7_DebugDM.SendWS(Rev); try frm_op_seae.DealAnswer(_result); finally end; end; procedure DwThread.ThFail; var _i: integer; begin //没获得正确回复时 try //Form_Opt_File.Thread_Dec(JZQNO); //Form_Opt_File.AfterThFail(JZQNO); except end; end; end.