近来研究 delphi 与 asp 之间如何
通信,最后使用 TIdHTTP 组件实现,测试代码实现简单的了乘 法计算, 重要过程是,先由 delphi 客户端发送两个数,由 add.asp 进行计算并返回结果。 简单代码如下: 简单代码如下: ----------------//code of delphi//-----------------------------------procedure TForm1.Button1Click(Sender: TObject); var no1:String; no2:string; PostURL :String; sParams :String; aParams :TStrings; aStream :TStringStream; begin IdHTTP1 := TIdHTTP.Create(nil); aParams := TStringList.Create; aStream := TStringStream.Create(''); form1.Edit4.Clear;//清空结果区 no1:=edit1.Text ; no2:=edit2.Text ; PostURL := 'localhost/add.asp?no1='no1+; //提交网址 sParams := 'no2='+no2; //参数 try aParams.Clear; aParams.Add(sParams); IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded'; IdHTTP1.Post(PostURL, aParams, aStream); //提交 form1.Edit4.Text:=astream.DataString;//获取结果 finally IdHTTP1.Free; aParams.Free; aStream.Free; end; end; ------------//code of asp//----------------------------------------<% 'code of add.asp dim no1,no2,isok,msg,jg no1=trim(request("name")) no2=trim(request("no2")) if no1="" then
isok=true msg="乘数 1 无效!" else isok=false end if if no2="" then isok=true msg="乘数 2 无效!" else isok=false end if if isok=true then response.write msg else jg=no1*no2 response.write jg end if %>
_end