我制作了一个程序,允许用户使用WebBrowser控件登录我们的CRM系统(ConnectWise) 然后,cookie将被移动到Web客户端控件,在那里它将解析一个带有.csv文件的URL。然后,Webclient会将csv下载到" C:\ Temp \ unassigned.csv"然后我会使用这个文件在程序中做其他事情。
这个工作好几个月,直到Connectwise的更新导致使用HTTPOnly Cookies,我无法从Web浏览器控件中提取cookie。 WebBrowser1.Document.Cookie字符串现在为空。
以下是代码:
Private Sub Internetr()
If WebBrowser1.Url.ToString.StartsWith("REDACTED") Then 'if connectwise is logged in
Dim _url As String = "REDACTED"
Dim _filename As String = ("C:\Temp\unassigned.csv")
WebBrowser1.Visible = False 'Hide the webbrowser
Refresh.Enabled = True 'Enable the ticker
Dim csv As WebClient = New WebClient 'new download webclient
'THIS IS WHERE I MOVED THE COOKIES FROM WEB BROWSER TO WEBCLIENT BEFORE
Try
csv.DownloadFile(_url, _filename)
load.Text = "Updating List..."
csv.Dispose()
DoUnassigned()
Catch ex As Exception
load.Text = "Failed to update list, Last updated at: " & gettime
debugbtn.Visible = True
exception = ex.ToString
Failed()
End Try
Else
WebBrowser1.Visible = True 'if not logged in, show the webbrowser
End If
End Sub
有人有任何想法吗?