我调用InternetOpen,InternetConnect,HttpOpenRequest,HttpSendRequest这几个API做了个软件验证登录帐号是否正确,每次登录网站前我想清除掉Cookie再登录不用上次登录的Cookie要怎么做呢?function GetWebPage(const URLA,URLB,FTPostQuery:string):string;
var
Session,
hConnect,hRequest:HINTERNET;
szSizeBuffer:Pointer;
dwLengthSizeBuffer:DWord;
dwReserved:DWord;
dwFileSize:DWord;
dwBytesRead:DWord;
Contents:PChar;
AcceptType:LPStr;
TOPA:String;
begin
 Session:=InternetOpen('',0,niL,niL,0);
 hConnect := InternetConnect(Session,Pchar(URLA),80, nil, nil,INTERNET_SERVICE_HTTP, 0, 0);
 AcceptType := PChar('Accept: */*');
 hRequest := HttpOpenRequest(hConnect, 'POST',PChar(URLB), 'HTTP/1.0',nil, @AcceptType, INTERNET_FLAG_RELOAD, 0);
 //----------------------------------------------------------
 TOPA:='Content-Type: application/x-www-form-urlencoded';
 HttpAddRequestHeaders(hRequest,PChar(TOPA),Length(TOPA),HTTP_ADDREQ_FLAG_ADD);
 TOPA:='Accept-Language: zh-cn';
 HttpAddRequestHeaders(hRequest,PChar(TOPA),Length(TOPA),HTTP_ADDREQ_FLAG_ADD);
 TOPA:='Referer: http://www.163.com';
 HttpAddRequestHeaders(hRequest,PChar(TOPA),Length(TOPA),HTTP_ADDREQ_FLAG_ADD);
 //----------------------------------------------------------
 HttpSendRequest(hRequest, nil,0,PChar(FTPostQuery), Length(FTPostQuery));
 dwLengthSizeBuffer:=1024;
 HttpQueryInfo(hRequest,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved);
 GetMem(Contents,dwFileSize);
 InternetReadFile(hRequest,Contents,dwFileSize,dwBytesRead);
 InternetCloseHandle(hRequest);
 InternetCloseHandle(Session);
 InternetCloseHandle(hConnect);
 Result:=StrPas(Contents);
 FreeMem(Contents);
end;

解决方案 »

  1.   

    可以试一下将cookies文件夹内容全部删除,如将C:\Documents   and   Settings\Administrator\Cookies文件夹下文件及文件夹全部删除,这里的Administrator是你登陆windows的用户名,这个应该很好获取//取得目录
    function GetCookiesFolder:string; 
    var 
            pidl:pItemIDList; 
            buffer:array [ 0..255 ] of char ; 
    begin 
           SHGetSpecialFolderLocation( 
             application.Handle , CSIDL_COOKIES, pidl); 
           SHGetPathFromIDList(pidl, buffer);  
           result:=strpas(buffer);  
    end;  
    function ShellDeleteFile(sFileName: string): Boolean;  
    var  
          FOS: TSHFileOpStruct;  
    begin  
           FillChar(FOS, SizeOf(FOS), 0); {记录清零}  
           with FOS do  
           begin  
               wFunc := FO_DELETE;//删除  
               pFrom := PChar(sFileName);  
               fFlags := FOF_NOCONFIRMATION;  
           end;  
           Result := (SHFileOperation(FOS) = 0);  
    end;//删除cookies  
    procedure DelCookie;  
    var  
           dir:string;  
    begin  
          try  
           InternetSetOption(nil, INTERNET_OPTION_END_BROWSER_SESSION, nil, 0);  
           dir:=GetCookiesFolder; 
           ShellDeleteFile(dir+'\*.txt'+#0); 
           except 
           abort;  
          end;  
     
    end;
      

  2.   

    这样删除的好像是IE的COOKIE吧?这个API用的不是IE的Cookie不知道他是放哪里的
      

  3.   

    WINDOWS的COOKIE都是一样的,其实还是用的IE的.
    function GetCookiesFolder:string; 
    var 
            pidl:pItemIDList; 
            buffer:array [ 0..255 ] of char ; 
    begin 
           SHGetSpecialFolderLocation( 
             application.Handle , CSIDL_COOKIES, pidl); 
           SHGetPathFromIDList(pidl, buffer);  
           result:=strpas(buffer);  
    end;  
    function ShellDeleteFile(sFileName: string): Boolean;  
    var  
          FOS: TSHFileOpStruct;  
    begin  
           FillChar(FOS, SizeOf(FOS), 0); {记录清零}  
           with FOS do  
           begin  
               wFunc := FO_DELETE;//删除  
               pFrom := PChar(sFileName);  
               fFlags := FOF_NOCONFIRMATION;  
           end;  
           Result := (SHFileOperation(FOS) = 0);  
    end;  
     
    //删除cookies  
    procedure DelCookie;  
    var  
           dir:string;  
    begin  
          try  
           InternetSetOption(nil, INTERNET_OPTION_END_BROWSER_SESSION, nil, 0);  
           dir:=GetCookiesFolder; 
           ShellDeleteFile(dir+'\*.txt'+#0); 
           except 
           abort;  
          end;  
     
    end; function GetCookiesFolder:string;
    var
      

  4.   

    cookie的文件夹路径保存在注册表   
      HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell   Folders\Cookies   这一项里面
      

  5.   

    procedure DeleteIECache; // 清理IE缓存,IE.cookies
    var
      lpEntryInfo: PInternetCacheEntryInfo;
      hCacheDir: LongWord;
      dwEntrySize: LongWord;
      cachefile: string;
      i: integer;
      cancheqqlist: TStringList;
    begin
      cancheqqlist := TStringList.Create;
      cancheqqlist.Clear;
      dwEntrySize := 0;
      FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);
      GetMem(lpEntryInfo, dwEntrySize);
      if dwEntrySize > 0 then
        lpEntryInfo^.dwStructSize := dwEntrySize;
      hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
      if hCacheDir <> 0 then
      begin
        repeat
          if (lpEntryInfo^.CacheEntryType) and (NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY then
            cachefile := pchar(lpEntryInfo^.lpszSourceUrlName);
          if (pos('www.juntnet.net', cachefile) > 0) or (pos('gamelint.xml', cachefile) > 0)  then    //清除特定网站的cookies.例如.www.kumusic.net.cn
            cancheqqlist.Add(cachefile);
          for i := 0 to cancheqqlist.Count - 1 do
            DeleteUrlCacheEntry(pchar(cancheqqlist.Strings[i])); //执行删除操作
          FreeMem(lpEntryInfo, dwEntrySize);
          dwEntrySize := 0;
          FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
          GetMem(lpEntryInfo, dwEntrySize);
          if dwEntrySize > 0 then
            lpEntryInfo^.dwStructSize := dwEntrySize;
        until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize);
      end;
      FreeMem(lpEntryInfo, dwEntrySize);
      FindCloseUrlCache(hCacheDir);
      cancheqqlist.Free;
    end;
      

  6.   


    procedure DeleteIECache; // 清理IE缓存,IE.cookies
    var
      lpEntryInfo: PInternetCacheEntryInfo;
      hCacheDir: LongWord;
      dwEntrySize: LongWord;
      cachefile: string;
      i: integer;
      cancheqqlist: TStringList;
    begin
      cancheqqlist := TStringList.Create;
      cancheqqlist.Clear;
      dwEntrySize := 0;
      FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);
      GetMem(lpEntryInfo, dwEntrySize);
      if dwEntrySize > 0 then
        lpEntryInfo^.dwStructSize := dwEntrySize;
      hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
      if hCacheDir <> 0 then
      begin
        repeat
          if (lpEntryInfo^.CacheEntryType) and (NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY then
            cachefile := pchar(lpEntryInfo^.lpszSourceUrlName);
          if (pos('www.juntnet.net', cachefile) > 0) or (pos('gamelint.xml', cachefile) > 0)  then    //清除特定网站的cookies.例如.www.kumusic.net.cn
            cancheqqlist.Add(cachefile);
          for i := 0 to cancheqqlist.Count - 1 do
            DeleteUrlCacheEntry(pchar(cancheqqlist.Strings[i])); //执行删除操作
          FreeMem(lpEntryInfo, dwEntrySize);
          dwEntrySize := 0;
          FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
          GetMem(lpEntryInfo, dwEntrySize);
          if dwEntrySize > 0 then
            lpEntryInfo^.dwStructSize := dwEntrySize;
        until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize);
      end;
      FreeMem(lpEntryInfo, dwEntrySize);
      FindCloseUrlCache(hCacheDir);
      cancheqqlist.Free;
    end;