Cookieの設定と取得 <TOP>
クッキーの設定と取得をテストします。
InternetSetCookie IEにCookie を設定
InternetGetCookie IEからCookie を取得

日付を設定した場合、下記のようにCookiesフォルダに保存されます。

'================================================================ '= Cookieの設定と取得
'= (InternetGetCookie.bas)
'================================================================
#include "Windows.bi"
' IEにCookieを設定
Declare Function Api_InternetSetCookie& Lib "wininet" Alias "InternetSetCookieA" (ByVal lpszUrlName$, ByVal lpszCookieName$, ByVal lpszCookieData$) As Long
' IEからCookieを取得
Declare Function Api_InternetGetCookie& Lib "wininet" Alias "InternetGetCookieA" (ByVal lpszUrlName$, ByVal lpszCookieName$, ByVal lpszCookieData$, lpdwSize&) As Long
'================================================================
'=
'================================================================
Declare Function Index bdecl () As Integer
Function Index()
Index = Val(Mid$(GetDlgRadioSelect("Radio1"), 6)) - 1
End Function
'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
Var Ret As Integer
If Index = 0 Then
'クッキーの作成(メモリ)
Ret = Api_InternetSetCookie("http://www.testcom.index.htm", "tokovalue", "TestData")
Else
'持続的なクッキーの作成(HDDに保存される)
Ret = Api_InternetSetCookie("http://www.testcom.index.htm", "tokovalue", "TestData; expires = Sat, 23-Sep-2006 06:00:00 GMT")
End If
If Ret = False Then
A% = MessageBox(GetWindowtext, "失敗!", 0, 2)
End If
End Sub
'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
Var Buffer As String * 256
Var Ret As Integer
Ret = Api_InternetGetCookie("http://www.testcom.index.htm", "tokovalue", Buffer, 255)
If Ret = False Then
A% = MessageBox(GetWindowtext, "失敗!", 0, 2)
Else
A% = MessageBox(GetWindowtext, Buffer, 0, 2)
End If
End Sub
'================================================================
'=
'================================================================
While 1
WaitEvent
Wend
Stop
End