提取cookievar sCookie:string; i:Integer; begin sCookie:=''; for i:=0 to IdHTTP1.Response.RawHeaders.Count-1 do begin if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10))='SET-COOKIE' then begin sCookieTmp:=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT)); sCookieTmp:=Copy(sCookieTmp,1,Pos(';',sCookieTmp)-1); sCookie:=sCookie+sCookieTmp+'; '; end; end; end;再把取得的sCookie传给IdHTTP1 IdHTTP1.Request.CustomHeaders.Add('Cookie: '+sCookie);再比如发表评论IdHTTP1.Post....................就OK
IDHTTP1.Response.RawHeaders.TEXT中 提取COOKIE然后要提交时 再添加
IDHTTP1.Request.CustomHeaders.Text := 'Cookie: '+ sCookie;
IDHTTP1.Response.RawHeaders.TEXT中 提取COOKIE中的cookies 就是 IDHTTP1.Request.CustomHeaders.Text := 'Cookie: '+ sCookie; 这里的scookie ?
POST 提交的数据怎么写? 能不能具体一点
就是idhttp post包的内容
IdHTTP1.Request.CacheControl:='no-cache'; sPost:=TStringStream.Create('');
try
sPost.WriteString('user='+'username'+'&'+
'pwd='+'123456'
);//
try
IdHTTP1.Post('http://www.youname.com',sPost);
except
end;
finally
sPost.Free;
end;
sCookie:string;
i:Integer;
begin
sCookie:='';
for i:=0 to IdHTTP1.Response.RawHeaders.Count-1 do
begin
if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10))='SET-COOKIE' then
begin
sCookieTmp:=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT));
sCookieTmp:=Copy(sCookieTmp,1,Pos(';',sCookieTmp)-1);
sCookie:=sCookie+sCookieTmp+'; ';
end;
end;
end;再把取得的sCookie传给IdHTTP1 IdHTTP1.Request.CustomHeaders.Add('Cookie: '+sCookie);再比如发表评论IdHTTP1.Post....................就OK
回去再看 对于idhttp的cookie我也是遇到问题