gpt4 book ai didi

vb.net - 在VB中通过WebBrowser发送Cookie

转载 作者:行者123 更新时间:2023-12-04 05:37:34 24 4
gpt4 key购买 nike

所以我已经发送了近两个小时来寻找答案,但没有任何效果。我需要通过我的 webbrowser 对象发送一些 cookie,但由于某种原因,我的 PHP 文件没有读取这些 cookie:

<?php die('Your username is '.$_COOKIE['user']); ?>

和我的 VB 代码来发送 cookie:
For i = 0 To 4
uploadBoxes(i).Navigate("about:blank")
uploadBoxes(i).Document.Cookie = "user=" & username.Text
uploadBoxes(i).Navigate("http://*****/uploader/app.php")
Next i

同样,任何帮助将不胜感激,是的,我确实需要通过 webbrowser 对象发送它。我也浏览过 MSDN 数据库,即使这样也没有说明这个问题。

- - - - - - - - - - - - - - - - - - - - - 答案 - - - -------------------------------------

所以我采用了 InternetSetCookie 方法并想出了这段用于制作 cookie 的代码:
Imports System.Runtime.InteropServices

' No more data is available.
Const ERROR_NO_MORE_ITEMS = 259

' The data area passed to a system call is too small.
Const ERROR_INSUFFICIENT_BUFFER = 122

Private Declare Function InternetSetCookie Lib "wininet.dll" _
Alias "InternetSetCookieA" _
(ByVal lpszUrlName As String, _
ByVal lpszCookieName As String, _
ByVal lpszCookieData As String) As Boolean

Private sub something()
Dim bRet As Boolean
bRet = InternetSetCookie("http://*****/uploader/app.php", _
"user", "admin")
If bRet = False Then
MsgBox("Failed")
End If
uploadBoxes(i).Navigate("http:/*****/uploader/app.php")
End sub

最佳答案

http://pinvoke.net/default.aspx/wininet.InternetSetCookie

  <DllImport("wininet.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function InternetSetCookie(lpszUrl As String, _
lpszCookieName As String, lpszCookieData As String) As Boolean
End Function

Imports System.Runtime.InteropServices
Sub InternetSetCookiePseudoCode()
'`CookieCollection` was populated using HttpWebRequest/Response calls
Dim i As Integer = 0
InternetSetCookie("https://www.url.com/", Nothing, CookieCollection(i).ToString() & "; expires = Sun, 01-Jul-2014 00:00:00 GMT")
'repeat for however many cookies you've got

browser.Navigate("https://www.url.com/", True)
End Sub

关于vb.net - 在VB中通过WebBrowser发送Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11729596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com