3

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?

user1613512
  • 3,590
  • 8
  • 28
  • 32
  • Have you considered standard .NET web request building? See for example [this page](http://stackoverflow.com/questions/3562979/making-a-web-request-to-a-web-page-which-requires-windows-authentication) with details about Windows authentication. – Anton Schwaighofer Jan 11 '17 at 13:16

1 Answers1

5

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.

Community
  • 1
  • 1
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553