Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# Data http request using Windows credentials

Tags:

f#

f#-data

I'm trying to get some html from a page hosting by IIS where Windows authentication is enabled.

So far I have:

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

What do I need to add in the headers list?

like image 837
user1613512 Avatar asked Jun 05 '26 03:06

user1613512


1 Answers

I'd agree with Anton that if you need further customization, then using the raw .NET API for making the request might be easier. That said, the RequestString does have a parameter customizeHttpRequest which lets you specify a function that sets other properties of the request before it is sent, so you can use the following to set the Credentials property:

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) 

For more information about what properties to configure, have a look at the .NET question that Anton mentioned in a comment.

like image 133
Tomas Petricek Avatar answered Jun 08 '26 00:06

Tomas Petricek