用httpid控件 使用TIdHTTP控件进行页面访问 procedure MSG(var theuser:TUserInfo); var Url: string; tempstr:widestring; Response : TStringStream; Request : TStrings;//用于存贮传向目的页面的信息,随Request传送,将自动封装于Form中 sqlid,code,status:string; temp:integer; mystringlist:TStringList; begin ////////////IdHTTP_main是个TIdHTTP控件 Response := TStringStream.Create(''); Request := TStringList.Create ; try Url:='http://coderClub/sms/hz/xx.asp'; Request.Append('seqid='+theuser.SeqID); Request.Append('mobile='+theuser.Mob); Request.Append('spcode='+theuser.Spc); Request.Append('msg='+theuser.Msg); Service1.IdHTTP_main.Request.ContentType :='application/x-www-form-urlencoded'; Service1.IdHTTP_main.Post(Url,Request,Response); //Response.DataString存贮着返回页面的html代码,本例以一下方式获得其中信息 tempstr:=LowerCase(Response.DataString); tempstr:=LeftStr(tempstr,pos('</returndeliver>',tempstr)+16); temp:=pos('<seqid>',tempstr); sqlid:=MidStr(tempstr,pos('<seqid>',tempstr)+7,pos('</seqid>',tempstr)-temp-7); if not IsNumber(sqlid) then begin mystringlist:=TStringList.Create; if FileExists(ExtractFilePath(Paramstr(0))+'Err.txt') then mystringlist.LoadFromFile(ExtractFilePath(Paramstr(0))+'Err.txt'); mystringlist.Add('('+DateTimeToStr(Now)+')seqid('+sqlid+')未知'); mystringlist.SaveToFile(ExtractFilePath(Paramstr(0))+'Err.txt'); mystringlist.Free; end else begin code:=MidStr(tempstr,pos('<code>',tempstr)+6,pos('</code>',tempstr)-pos('<code>',tempstr)-6); if not IsNumber(code) then begin mystringlist:=TStringList.Create; if FileExists(ExtractFilePath(Paramstr(0))+'Err.txt') then mystringlist.LoadFromFile(ExtractFilePath(Paramstr(0))+'Err.txt'); mystringlist.Add(DateTimeToStr(Now)+'[sqlid:'+sqlid+']错误码未知'); mystringlist.SaveToFile(ExtractFilePath(Paramstr(0))+'Err.txt'); mystringlist.Free; code:='1'; status:='(错误码未知)'; end; status:=status+MidStr(tempstr,pos('<status>',tempstr)+8,pos('</status>',tempstr)-pos('<status>',tempstr)-8); with Service1.ADOQuery_temp do begin Connection:=conn_Client; Close; SQL.Clear; SQL.Add('update '+GameInfo.deliver_table_log+' set code='+code+',status='''+status+''' where seqid='+theuser.SeqID); ExecSQL; end; end; finally Request.Free ; Response.Free ; end; //////////// end;
使用TIdHTTP控件进行页面访问
procedure MSG(var theuser:TUserInfo);
var
Url: string;
tempstr:widestring;
Response : TStringStream;
Request : TStrings;//用于存贮传向目的页面的信息,随Request传送,将自动封装于Form中
sqlid,code,status:string;
temp:integer;
mystringlist:TStringList;
begin
////////////IdHTTP_main是个TIdHTTP控件
Response := TStringStream.Create('');
Request := TStringList.Create ;
try
Url:='http://coderClub/sms/hz/xx.asp';
Request.Append('seqid='+theuser.SeqID);
Request.Append('mobile='+theuser.Mob);
Request.Append('spcode='+theuser.Spc);
Request.Append('msg='+theuser.Msg);
Service1.IdHTTP_main.Request.ContentType :='application/x-www-form-urlencoded';
Service1.IdHTTP_main.Post(Url,Request,Response);
//Response.DataString存贮着返回页面的html代码,本例以一下方式获得其中信息
tempstr:=LowerCase(Response.DataString);
tempstr:=LeftStr(tempstr,pos('</returndeliver>',tempstr)+16);
temp:=pos('<seqid>',tempstr);
sqlid:=MidStr(tempstr,pos('<seqid>',tempstr)+7,pos('</seqid>',tempstr)-temp-7);
if not IsNumber(sqlid) then
begin
mystringlist:=TStringList.Create;
if FileExists(ExtractFilePath(Paramstr(0))+'Err.txt') then
mystringlist.LoadFromFile(ExtractFilePath(Paramstr(0))+'Err.txt');
mystringlist.Add('('+DateTimeToStr(Now)+')seqid('+sqlid+')未知');
mystringlist.SaveToFile(ExtractFilePath(Paramstr(0))+'Err.txt');
mystringlist.Free;
end
else
begin
code:=MidStr(tempstr,pos('<code>',tempstr)+6,pos('</code>',tempstr)-pos('<code>',tempstr)-6);
if not IsNumber(code) then
begin
mystringlist:=TStringList.Create;
if FileExists(ExtractFilePath(Paramstr(0))+'Err.txt') then
mystringlist.LoadFromFile(ExtractFilePath(Paramstr(0))+'Err.txt');
mystringlist.Add(DateTimeToStr(Now)+'[sqlid:'+sqlid+']错误码未知');
mystringlist.SaveToFile(ExtractFilePath(Paramstr(0))+'Err.txt');
mystringlist.Free;
code:='1';
status:='(错误码未知)';
end;
status:=status+MidStr(tempstr,pos('<status>',tempstr)+8,pos('</status>',tempstr)-pos('<status>',tempstr)-8);
with Service1.ADOQuery_temp do
begin
Connection:=conn_Client;
Close;
SQL.Clear;
SQL.Add('update '+GameInfo.deliver_table_log+' set code='+code+',status='''+status+''' where seqid='+theuser.SeqID);
ExecSQL;
end; end;
finally
Request.Free ;
Response.Free ;
end; ////////////
end;