我用同一个idhttp组建,执行GET和POST操作,GET没问题,POST始终不对(获取数据包,失踪header不正确),请高手执教
procedure TForm1.Button1Click(Sender: TObject);
var
xx:string;
xxx:tstrings;
yy:TMemoryStream;
jpg:Tjpegimage;
begin
idhttp1.Request.Connection:='Keep-Alive';
idhttp1.Request.CacheControl:='no-cache';
xxx:=tstringlist.Create;
yy := TMemoryStream.Create ;
xx:=IdHTTP1.Get('http://login.tom.com/captcha/drawme.php?type=6');
xxx:=SplitString(xx,'=');
IdHTTP1.Get('http://login.tom.com/captcha/draw.php?post_key='+stringreplace(xxx[8],';expires','',[rfReplaceAll])+'&type=6',yy);
if StreamType(yy)='JPEG' then begin
yy.Position:=0;
try
Jpg:=tjpegimage.Create;
Jpg.LoadFromStream(yy);
image1.Picture.Graphic:= Jpg;
finally
Jpg.Free;
end;
end else if StreamType(yy)='BMP' then begin
yy.Position:=0;
image1.Picture.Bitmap.LoadFromStream(yy);
end else if StreamType(yy)='PNG' then begin
end;
end; procedure TForm1.Button2Click(Sender: TObject);
var
ParaList:tStringList;
str:string;
begin
ParaList:=tstringlist.Create;
idhttp1.Request.Connection:='Keep-Alive';
idhttp1.Request.CacheControl:='no-cache';
idhttp1.request.contenttype:='application/x-www-form-urlencoded';
try
ParaList.Add('funcid=reguser');
ParaList.Add('rf=060702');
ParaList.Add('refer=http://mail.tom.com');
ParaList.Add('year=1980');
ParaList.Add('month=1');
ParaList.Add('day=1');
ParaList.Add('uid=fsdads35sdf');
ParaList.Add('password=111111qq');
ParaList.Add('confirm_password=111111qq');
ParaList.Add('[email protected]');
ParaList.Add('authcode='+edit1.Text);
ParaList.Add('argee=1');
str:=idhttp1.Post('http://bjcgi.tom.com/cgi-bin/tom_reg.cgi?rf=060702',paralist);
WB_LoadHTML(WebBrowser1,str);
finally
ParaList.Free;
end; end; 以上代码同样设置idhttp1.Request.Connection:='Keep-Alive';
但是GET获取的数据包header是正确的Connection: Keep-Alive,但是POST获取的数据包确是Connection: close,包括idhttp1.Request.CacheControl:='no-cache';也没有生效
procedure TForm1.Button1Click(Sender: TObject);
var
xx:string;
xxx:tstrings;
yy:TMemoryStream;
jpg:Tjpegimage;
begin
idhttp1.Request.Connection:='Keep-Alive';
idhttp1.Request.CacheControl:='no-cache';
xxx:=tstringlist.Create;
yy := TMemoryStream.Create ;
xx:=IdHTTP1.Get('http://login.tom.com/captcha/drawme.php?type=6');
xxx:=SplitString(xx,'=');
IdHTTP1.Get('http://login.tom.com/captcha/draw.php?post_key='+stringreplace(xxx[8],';expires','',[rfReplaceAll])+'&type=6',yy);
if StreamType(yy)='JPEG' then begin
yy.Position:=0;
try
Jpg:=tjpegimage.Create;
Jpg.LoadFromStream(yy);
image1.Picture.Graphic:= Jpg;
finally
Jpg.Free;
end;
end else if StreamType(yy)='BMP' then begin
yy.Position:=0;
image1.Picture.Bitmap.LoadFromStream(yy);
end else if StreamType(yy)='PNG' then begin
end;
end; procedure TForm1.Button2Click(Sender: TObject);
var
ParaList:tStringList;
str:string;
begin
ParaList:=tstringlist.Create;
idhttp1.Request.Connection:='Keep-Alive';
idhttp1.Request.CacheControl:='no-cache';
idhttp1.request.contenttype:='application/x-www-form-urlencoded';
try
ParaList.Add('funcid=reguser');
ParaList.Add('rf=060702');
ParaList.Add('refer=http://mail.tom.com');
ParaList.Add('year=1980');
ParaList.Add('month=1');
ParaList.Add('day=1');
ParaList.Add('uid=fsdads35sdf');
ParaList.Add('password=111111qq');
ParaList.Add('confirm_password=111111qq');
ParaList.Add('[email protected]');
ParaList.Add('authcode='+edit1.Text);
ParaList.Add('argee=1');
str:=idhttp1.Post('http://bjcgi.tom.com/cgi-bin/tom_reg.cgi?rf=060702',paralist);
WB_LoadHTML(WebBrowser1,str);
finally
ParaList.Free;
end; end; 以上代码同样设置idhttp1.Request.Connection:='Keep-Alive';
但是GET获取的数据包header是正确的Connection: Keep-Alive,但是POST获取的数据包确是Connection: close,包括idhttp1.Request.CacheControl:='no-cache';也没有生效
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货