新之助meow

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 未分类
  3. 正文

webBrowser1.Document.Cookie 获取不到带httponly的cookie的解决方法 vb版本

2019年10月30日 620点热度 22人点赞 0条评论

有几个前提
添加到ie的可信站点区域
不能是基于session的cookie
注意url的路径,有些cookie下发是带路径的,获取时不带路径获取不到


#调用时要注意,url最后要有/  否则某些带路径的cookie获取不到
#获取cookie调用
httpOnlyCookie =GetCookieInternal(New Uri("http://192.168.0.1:10051/web/"), True)  

<SuppressUnmanagedCodeSecurity, SecurityCritical, DllImport("wininet.dll", EntryPoint:="InternetGetCookieExW", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True)>
    Friend Shared Function InternetGetCookieEx(<[In]> Url As String, <[In]> cookieName As String, <Out> cookieData As StringBuilder, <[In], Out> ByRef pchCookieData As UInteger, flags As UInteger, reserved As IntPtr) As Boolean
    End Function
    Private Const INTERNET_COOKIE_HTTPONLY As Integer = &H2000
    Public Shared Function GetCookieInternal(inuri As Uri, throwIfNoCookie As Boolean) As String

        Dim pchCookieData As Integer = 0
        Dim url As String 
        url = inuri.AbsoluteUri
        Dim flag As UInteger = INTERNET_COOKIE_HTTPONLY 'NativeMethods.InternetFlags.INTERNET_COOKIE_HTTPONLY;

        'Gets the size of the string builder   
        If (InternetGetCookieEx(url, Nothing, Nothing, pchCookieData, flag, IntPtr.Zero)) Then
            pchCookieData = pchCookieData + 1
            Dim cookieData As StringBuilder = New StringBuilder(pchCookieData)

            'Read the cookie   
            If (InternetGetCookieEx(url, Nothing, cookieData, pchCookieData, flag, IntPtr.Zero)) Then

                DemandWebPermission(inuri)
                Return cookieData.ToString()
            End If
        End If

        Dim lastErrorCode As Integer = Marshal.GetLastWin32Error()

        If (throwIfNoCookie And (lastErrorCode <> 259)) Then  'NativeMethods.ErrorFlags.ERROR_NO_MORE_ITEMS

            Throw New System.ComponentModel.Win32Exception(lastErrorCode)
        End If

        Return Nothing
    End Function

    Private Shared Sub DemandWebPermission(inuri As Uri)

        Dim uriString As String = UriToString(inuri)

        If (inuri.IsFile) Then

            Dim localPath As String = inuri.LocalPath
            Dim FIP = New FileIOPermission(FileIOPermissionAccess.Read, localPath)
            FIP.Demand()

        Else

            Dim WP = New WebPermission(NetworkAccess.Connect, uriString)
            WP.Demand()
        End If
    End Sub

参考

webBrowser1.Document.Cookie取不到HttpOnly的Cookie,取Cookie不完整
https://blog.csdn.net/smeller/article/details/7022370

Send Cookie through WebBrowser in VB
https://stackoverflow.com/questions/11729596/send-cookie-through-webbrowser-in-vb

InternetGetCookieEx: not working
https://stackoverflow.com/questions/18262653/internetgetcookieex-not-working

标签: 暂无
最后更新:2019年10月30日

tjccn_wx@hotmail.com

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 10 月
  • 2024 年 2 月
  • 2023 年 7 月
  • 2023 年 1 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 6 月
  • 2022 年 4 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 9 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2019 年 10 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2018 年 1 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月
  • 2017 年 6 月
  • 2017 年 5 月
  • 2017 年 4 月
  • 2017 年 3 月
  • 2017 年 2 月
  • 2017 年 1 月
  • 2016 年 12 月
  • 2016 年 11 月
  • 2016 年 10 月
  • 2016 年 9 月
  • 2016 年 8 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 5 月
  • 2016 年 4 月
  • 2016 年 3 月
  • 2015 年 12 月
  • 2015 年 8 月

分类

  • android
  • mysql
  • nethunter
  • proxmark
  • 未分类

COPYRIGHT © 2026 新之助meow. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang