自己DING下,
感谢上面各位的答复,问题解决了第一步,发送及取值均无问题.大家共同进步,偶把正确代码共享.
但!
但,使用IDHTTP控件实现时,如果仅仅执行一次POST,程序是完全正确的. 如果加入到循环体中多次执行POST则会报错!程序中断!!请教各位了.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, ComCtrls;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
StatusBar1: TStatusBar;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
myParams:TStringList;
ret:TStringStream;
i:integer;
begin
for i:=1 to 5 do
begin
IdHTTP1.ReadTimeout := 30*1000; //设置超时时间30seconds
IdHttp1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHttp1.HTTPOptions := [hoForceEncodeParams];
ret := tstringstream.Create('');
myParams:=tstringlist.Create;
myparams.Add('lpath='+edit1.text);
myparams.Add('ldata='+memo1.text);
try
idhttp1.Post('http://localhost/call/accept%20sms.asp',myparams,ret); //idhttp提交post请求,
showmessage(ret.DataString); //返回页面源码
showmessage(idhttp1.ResponseText); //返回错误信息
except
memo1.Lines.Add('success?'); //发送记录完毕
end;
idhttp1.Disconnect;
FreeAndNil(idhttp1);
freeAndNil(myparams);
Ret.Position:=0;
memo1.Lines.LoadFromStream(ret);
ret.Free;
form1.Refresh;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close();
application.Terminate;
end;
end.