Delphi IDhttp 获取Cookie

获取post,或者get返回的cookie,除了过滤返回的字符串之外,最简单的方法是使用idhttp的CookieManager属性

比如获得IDhttp返回的全部Cookie

[delphi]  view plain  copy
 print ?
  1. if idhttp1.CookieManager.CookieCollection.Count > 0 then  
  2.     for i := 0 to idhttp1.CookieManager.CookieCollection.Count - 1 do  
  3.       temp := temp + idhttp1.CookieManager.CookieCollection.Items[i] .CookieText + ';';  

也可以通过属性名和属性值的形式获得,这样就可以提取出个别的Cookie值

[delphi]  view plain  copy
 print ?
  1. idhttp1.CookieManager.CookieCollection.Items[i]  
  2.           .CookieName idhttp1.CookieManager.CookieCollection.Items[i]  
  3.           .Value  

比如:

[delphi]  view plain  copy
 print ?
  1. temp := TStringList.Create;  
  2.   if idhttp1.CookieManager.CookieCollection.Count > 0 then  
  3.     for i := 0 to idhttp1.CookieManager.CookieCollection.Count - 1 do  
  4.       // temp := temp + idhttp1.CookieManager.CookieCollection.Items[i] .CookieText + ';';  
  5.       temp.Add(idhttp1.CookieManager.CookieCollection.Items[i]  
  6.           .CookieName + '=' + idhttp1.CookieManager.CookieCollection.Items[i]  
  7.           .Value);  

你可能感兴趣的:(Delphi)