How to log http requests in F#
You can pass a customization function to Http.Request, I think it would be OK to pass one that has a side effect of logging something about the request. For example:
open System.Net
open FSharp.Data
let requestHeaders =
[
"User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
"Accept", "*/*"
]
let requestCustomizeFunc =
fun (request: HttpWebRequest) ->
printfn "Address: %O" request.Address
printfn "Method: %O" request.Method
printfn "Headers: %O" request.Headers
request
[<EntryPoint>]
let main argv =
let response = Http.Request ("http://tomasp.net", headers = requestHeaders, customizeHttpRequest = requestCustomizeFunc)
response.StatusCode
|> printfn "%O"
0
This is quick and dirty; if you're really serious about logging what's going on at the network level in your .NET app, you probably want to consider taking advantage of the built-in tracing capability.
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/network-tracing