我用的是 Delphi 7 和 Indy 的 TidHttp 控件
对于有Session的主页进行 Post时,会出现过期等字样
下面是程序,求高手指点
//----------------------------------------------------
procedure TMainForm.btnRunClick(Sender: TObject);
var
Source: TStrings;
Response: TMemoryStream;
S, Cookie: String;
i: integer;
begin
Response := TMemoryStream.Create;
Source := TStringList.Create;
S := Http.Get(Page1);
Memo1.Text := S;
// 从返回的页面中找出cookie, 并增加到http.Request中
for i := 0 to Http.Response.RawHeaders.Count -1 do
if UpperCase(LeftStr(Http.Response.RawHeaders, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(Http.Response.RawHeaders, 12, MaxInt));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
Http.Request.RawHeaders.Add('Cookie:'+ Cookie);
end;
// 再去下一页, 先准备数据
Source.Clear;
Source.Add('USERnumber=' + UserName + '&pwd=' + PassWord + '&UserType=0'
+ '&imageField2.x=19&imageField2.y=8');
Memo1.Text := Http.Post(Page2, Source);
Source.Free;
Response.Free;
//----------------------------------------------------