我正在玩这个不错的教程中的一个简单的 f# 示例。并遇到了这个非常奇怪的错误。向 webrequest 添加代理后,它告诉我 WebProxy 类型与预期的 IWebProxy 类型不兼容。这有点奇怪,为什么我的 C# 锤子在 F# 中不起作用?
我在这里做错了什么?
let downloadUrlToFile url file =
let req = WebRequest.Create(Uri(url))
req.Proxy = new WebProxy("127.0.0.1", 444)
use res = req.GetResponse()
use stream = res.GetResponseStream()
use reader = new IO.StreamReader(stream)
let timestamp = DateTime.UtcNow.ToString("yyy-MM-dd")
let path = sprintf "%s.%s.html" file timestamp
use writer = new IO.StreamWriter(path)
writer.Write(reader.ReadToEnd())
printfn "done loading %s to %s" url file
错误信息
This expression was expected to have type
IWebProxy
but here has type
WebProxy