Recently, development requires data packet capture from the website, first use webbrowser to request the web page, get the element value, and then use idhttp to get the web page. Because it involves sign verification, login, etc., it has been unsuccessful. Later, using the network data packet capture tool, it was found that the data was the same when requesting with webbrowser and ID http, but the cookies were different.
1. Data packet capture settings cookies: Set-Cookie: JsessionID=4nLLYm1XrVtMWJL5VvG2y13RyXJbvhv2kth3SJ5hGpbL7Jv4ZTQk!1183038173!NONE; path=/; HttpOnly
2. Cookies when webbrowser request: JSESSIONID=QTnTYq6QyCvCBdyhtBRLP4K4WLzxGQ2LCSbDSNBF8zKDPqt1WMDJ!1003383531!-543092864; http:xxxxxxx=3071348908.44105.0000
3. Cookies during idhttp request: http:xxxxxxx=3071348908.44105.0000.
It turns out that (CookieWEB.documentasihtmldocument2).cookie cannot get all cookies in webbrowser. You need to use 'wininet.dll to get the complete cookie, and then assign it to idhttp to succeed.
function GetCookie(url: string): string;const INTERNET_COOKIE_HTTPONLY = $00002000; INTERNET_COOKIE_THIRD_PARTY = $00000010; INTERNET_FLAG_RESTRICTED_ZONE= $00020000;var hModule:THandle; InternetGetCookieEx: function(lpszUrl, lpszCookieName,lpszCookieData: PChar; var lpdwSize: DWord;dwFlags:DWORD;lPReserved : Pointer): BOOL;StdCall; CookieSize:DWORD; cookiedata:PWideChar; thebool:bool; began result := ''; hModule:=GetModuleHandle('wininet.dll'); if hModule<>0 then begin @InternetGetCookieEx:= GetProcAddress(hModule,'InternetGetCookieExW'); if @InternetGetCookieEx<>nil then begin CookieSize:=10240; Cookiedata := AllocMem(CookieSize); thebool:=InternetGetCookieEx(PWideChar(url),nil,CookieData,CookieSize,INTERNET_COOKIE_HTTPONLY,nil) ; if thebool then result := CookieData; FreeMem(Cookiedata); end; FreeLibrary(hModule); end; end; end;