RestSharp.dll というライブラリーを使います。
RestSharp.dll へのシンボリックリンクを コンパイル、実行するフォルダー内に作成します。
http_get.fs
// ----------------------------------------------------------------
//
// http_get.fs
//
// Mar/08/2018
//
// ----------------------------------------------------------------
open System
open RestSharp
// ----------------------------------------------------------------
[<EntryPoint>]
let main argv =
Console.Error.WriteLine("*** 開始 ***")
let host_in = "https://httpbin.org"
printfn "host_in = %s" host_in
let client = new RestClient(host_in)
let request = new RestRequest("/get", Method.GET)
let response = client.Execute(request)
let content = response.Content
printfn "%s" content
Console.Error.WriteLine("*** 終了 ***")
0
// ----------------------------------------------------------------
Makefile
http_get.exe : http_get.fs
fsharpc http_get.fs -r:RestSharp.dll
clean:
rm -f *.exe
コンパイル
$ make
fsharpc http_get.fs -r:RestSharp.dll
F# Compiler for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
実行結果
$ mono ./http_get.exe
*** 開始 ***
host_in = https://httpbin.org
{
"args": {},
"headers": {
"Accept": "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "0",
"Host": "httpbin.org",
"User-Agent": "RestSharp 104.1.0.0",
"X-Amzn-Trace-Id": "Root=1-62ef3c35-114a557008ed9e653a2a142b"
},
"origin": "219.126.135.211",
"url": "https://httpbin.org/get"
}
*** 終了 ***
Post の例はこちら
F# の http クライアントの使い方 (Post)