我的目标是从webBrowser控件检索cookie。我试着用引用来做,但是事件。Map不允许我返回值:
let getCookie(url:string) =
let form = new Form(Text="Internet Navigator")
form.AutoScaleDimensions <- new System.Drawing.SizeF(6.0F, 13.0F)
form.AutoScaleMode <- System.Windows.Forms.AutoScaleMode.Font
form.ClientSize <- new System.Drawing.Size(849, 593)
form.ResumeLayout(false)
form.PerformLayout()
let wb = new WebBrowser()
wb.Visible<-true
wb.AutoSize<-true
wb.Size <- new System.Drawing.Size(804, 800)
form.Controls.Add(wb)
form.Show()
let cookie = ref ""
wb.Navigate(url)
wb.DocumentCompleted
|> Event.map(fun _ -> cookie:= wb.Document.Cookie)
!cookie
理想情况下,有一种方法从Event.map
(或类似的东西)内返回cookie值?
UPDATED:从函数返回cookie值而不是使用回调
let getCookie(url:string) =
let form = new Form(Text="Internet Navigator")
form.AutoScaleDimensions <- new System.Drawing.SizeF(6.0F, 13.0F)
form.AutoScaleMode <- System.Windows.Forms.AutoScaleMode.Font
form.ClientSize <- new System.Drawing.Size(849, 593)
form.ResumeLayout(false)
form.PerformLayout()
let wb = new WebBrowser()
wb.Visible<-true
wb.AutoSize<-true
wb.Size <- new System.Drawing.Size(804, 800)
form.Controls.Add(wb)
wb.DocumentCompleted |> Event.add (fun _ -> form.Close())
wb.Navigate(url)
form.ShowDialog() |> ignore
wb.Document.Cookie
[<STAThreadAttribute>]
do
let cookie = getCookie "http://www.google.com"
Console.Read() |> ignore