如何使用 FSharp.Data 的用户名和密码
How to use a user name and password with FSharp.Data
我一直在看 FSharp.Data 包,看起来很有用,并且看过 how to do basic requests...
let html = Http.RequestString("http://example.com")
我想用它来访问 password-protected 页面,但不知道如何操作。查看 HttpRequestHeaders page,看起来我应该可以传递一些 headers 来包含信息,但我不确定该怎么做。
该页面链接到包含以下函数的代码示例...
let BasicAuth (username:string) (password:string) =
let base64Encode (s:string) =
let bytes = Encoding.UTF8.GetBytes(s)
Convert.ToBase64String(bytes)
sprintf "%s:%s" username password |> base64Encode |> sprintf "Basic %s" |> Authorization
...看起来它正在创建必要的信息,但我不知道接下来要做什么。
有人能帮忙吗?谢谢
BasicAuth 创建授权 HTTP 的值 header。
类似的东西(改编自http://fsharp.github.io/FSharp.Data/library/Http.html):
Http.RequestString
( "http://example.com/...", httpMethod = "GET",
headers = [ "Authorization", (BasicAuth "username" "password") ])
授权header上有很多资源,这个看起来不错:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
这张图表很不错:https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
我一直在看 FSharp.Data 包,看起来很有用,并且看过 how to do basic requests...
let html = Http.RequestString("http://example.com")
我想用它来访问 password-protected 页面,但不知道如何操作。查看 HttpRequestHeaders page,看起来我应该可以传递一些 headers 来包含信息,但我不确定该怎么做。
该页面链接到包含以下函数的代码示例...
let BasicAuth (username:string) (password:string) =
let base64Encode (s:string) =
let bytes = Encoding.UTF8.GetBytes(s)
Convert.ToBase64String(bytes)
sprintf "%s:%s" username password |> base64Encode |> sprintf "Basic %s" |> Authorization
...看起来它正在创建必要的信息,但我不知道接下来要做什么。
有人能帮忙吗?谢谢
BasicAuth 创建授权 HTTP 的值 header。
类似的东西(改编自http://fsharp.github.io/FSharp.Data/library/Http.html):
Http.RequestString
( "http://example.com/...", httpMethod = "GET",
headers = [ "Authorization", (BasicAuth "username" "password") ])
授权header上有很多资源,这个看起来不错:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
这张图表很不错:https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication