我试图从启用Windows身份验证的IIS主页获取一些HTML。
到目前为止,我有:
open FSharp.Data
[<EntryPoint>]
let main argv =
let html = Http.RequestString ("http://mywebsite.com/Detail.aspx", query=[("zip","9000");("date","11/01/2017")], headers=[???])
printf "%s" html
System.Console.ReadLine() |> ignore
0 // return an integer exit code
我需要在标题列表中添加什么内容?
答案 0 :(得分:4)
我同意Anton的观点,如果您需要进一步定制,那么使用原始.NET API来提出请求可能会更容易。也就是说,RequestString
确实有一个参数customizeHttpRequest
,它允许您指定在发送请求之前设置其他属性的函数,因此您可以使用以下内容设置Credentials
属性:
open System.Net
let html =
Http.RequestString("http://mywebsite.com/Detail.aspx",
query=[("zip","9000");("date","11/01/2017")],
customizeHttpRequest = fun r ->
r.Credentials <- new NetworkCredential( "username", "password", "domain" )
r)
有关要配置的属性的更多信息,请查看.NET question that Anton mentioned in a comment。