使用 Windows 凭据的 F# 数据 http 请求
F# Data http request using Windows credentials
我正在尝试从启用了 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
我需要在 headers 列表中添加什么?
我同意 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。
我正在尝试从启用了 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
我需要在 headers 列表中添加什么?
我同意 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。