*!*
Cookies 管理(删除/获取)
*!*
用法:首先打开你的浏览器中,输入:
https://bbs.bccn.net/
*!*
如果需要用户名和密码的,请输入:用户名:xxxxxxx 和 密码:yyyyyyy
*!*
等正常后,运行本代码,就可以过得你的 Cookie 的 Cook.txt 文件
*!*
InternetGetCookie() 只读取 Cookie 目录下生成的 Cookie
Clear
Do Declare
Local lcUrl, lcCookieName, lcCookieData, lnLen
lcUrl = "
https://bbs.bccn.net/" && 网址
lcCookieName = "user settings"
&& 定义 Cookie 名
lcCookieData = "regular,54,126,-1,0"
*
= AddPersistentCookie(lcUrl, lcCookieName,;
lcCookieData, date()+2)
? "Cookie:", ReadCookie(lcUrl, lcCookieName)
&& 读取 Cookie
* = DeleteCookie(lcUrl, lcCookieName)
&& 删除 Cookie
* =Strtofile(ReadCookie(lcUrl, lcCookieName), "Cook.txt")
&& 保存 Cookie 文件
Function ReadCookie(lcUrl, lcCookieName)
Local lcCookieData, lnLen, lcResult
lnLen = 4096
&& 预设接收结果的缓冲区的大小为:4KB
lcCookieData = Space(lnLen)
lcResult = ""
&& 预设接收的结果
If InternetGetCookie(lcUrl, lcCookieName, @lcCookieData, @lnLen) <> 0
lcResult = Left(lcCookieData, lnLen-1)
Else
* 259 = 没有可用的数据了。
Endif
Return lcResult
Endfunc
Procedure AddSessionCookie(lcUrl, lcCookieName, lcCookieData)
* 会话的 Cookie 被存储在内存中,可以通过创建它们的进程访问。
= InternetSetCookie(lcUrl, lcCookieName, lcCookieData)
Endproc
Procedure AddPersistentCookie(lcUrl, lcCookieName, lcCookieData, lvExpires)
* Persistent cookies are cookies that have an expiration date.
* These cookies are stored in the Windows\System directory.
= InternetSetCookie(lcUrl, lcCookieName,;
lcCookieData + ";expires=" + toGMTString(lvExpires))
Endproc
Procedure DeleteCookie(lcUrl, lcCookieName)
* To delete a persistent cookie you must set its expiry date
* to a time that has already expired.
* Usually it keeps staying as a session cookie after being deleted
= AddPersistentCookie(lcUrl, lcCookieName, "", Date()-1)
Endproc
Function toGMTString(ltDate)
* 返回 datetime 格式为 DAY, DD-MMM-YYYY HH:MM:SS GMT
Return Substr("SunMonTueWedThuFriSat",;
(Dow(ltDate,1)-1)*3+1, 3) + ", " +;
STRTR(Str(Day(ltDate), 2), " ","0") + "-" +;
SUBSTR("JanFebMarAprMayJunJulAugSepOctNovDec",;
(Month(ltDate)-1)*3+1, 3) + "-" +;
STR(Year(ltDate),4) + " " +;
STRTR(Str(Hour(ltDate), 2), " ","0") + ":" +;
STRTR(Str(Minute(ltDate), 2), " ","0") + ":" +;
STRTR(Str(Sec(ltDate), 2), " ","0") + " GMT"
Endfunc
Procedure Declare
Declare Integer InternetGetCookie In wininet;
STRING lpszUrlName, String lpszCookieName,;
STRING @lpszCookieData, Integer @lpdwSize
Declare Integer InternetSetCookie In wininet;
STRING lpszUrl, String lpszCookieName,;
STRING lpszCookieData
Endproc
[此贴子已经被作者于2017-6-6 16:27编辑过]