Access 2007 VBA で WinHTTP を使用して、Cookie ログイン資格情報 accountを必要とするアイテムのリストを取得しています。
まず、 https : //www.example.com/login.php から次のようにログインします。
Dim strCookie As String, strResponse As String, _
strUrl As String
'
Dim xobj As Object
'
Set xobj = New WinHttp.WinHttpRequest
'
strUrl = "https://www.example.com/login.php"
xobj.Open "POST", strUrl, False
xobj.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
xobj.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xobj.Send "username=johndoe2&password=mypassword"
'
strCookie = xobj.GetResponseHeader("Set-Cookie")
strResponse = xobj.ResponseText
strResponseの内容は、この文字列でjohndoe2が歓迎されているため、ログインに問題がないことを示しています。strCookieは、ログインの成功後に HTTP サーバーから返された Set-Cookie を保存します。
次に、ログインしたユーザーのみがアクセスできる機密ページを取得する必要があります: https://www.example.com/secret-contents.php。以前の Set-Cookie ヘッダーstrCookieを使用してこれを行い、サーバーに再送信します。
'
' now try to get confidential contents:
'
strUrl = "https://www.example.com/secret-contents.php"
xobj.Open "GET", strUrl, False
xobj.SetRequestHeader "Cookie", strCookie
xobj.Send
'
strCookie = xobj.GetResponseHeader("Set-Cookie")
strResponse = xobj.ResponseText
残念ながら、新しいstrResponseは、フェッチされたコンテンツが必要なコンテンツではなく、ログイン ページであることを示しているため、失敗しました。また、strCookieも変更されました。
これは、Cookie に基づく認証ではなく、有名な基本認証、NTLM 認証、ダイジェスト認証、および Kerberos 認証などの Windows/OS にリンクされた認証のみを対象としているため、テスト済みで効果はありません。
xobj.SetCredentials "johndoe2", "mypassword", 0
以前に認証された資格情報を使用するために、Set-Cookie 以外にヘッダーとしてリモート サーバーに送信するものは何ですか?
サーバーは、typo3 CMS フレームワークを使用します。