LoginSignup
1
1

More than 1 year has passed since last update.

F# の http クライアントの使い方 (Post)

Last updated at Posted at 2018-03-08

RestSharp.dll というライブラリーを使います。
RestSharp.dll へのシンボリックリンクを コンパイル、実行するフォルダー内に作成します。

http_post.fs
// ----------------------------------------------------------------
//
//	http_post.fs
//
//						Mar/08/2018
//
// ----------------------------------------------------------------
open System
open RestSharp
// ----------------------------------------------------------------
[<EntryPoint>]
let main argv =
    Console.Error.WriteLine("*** 開始 ***") 
    let host_in = "https://httpbin.org"
    let user = "jiro"
    let password = "123456"
    printfn "host_in = %s" host_in
//
    let client = new RestClient(host_in)
    let request = new RestRequest("/post", Method.POST)
    let _ = request.AddParameter("user", user)
    let _ = request.AddParameter("password", password)
//
    let response = client.Execute(request)
    let content = response.Content
    printfn "%s" content
    Console.Error.WriteLine("*** 終了 ***") 
    0
// ----------------------------------------------------------------
Makefile
http_post.exe : http_post.fs
	fsharpc http_post.fs -r:RestSharp.dll
clean:
	rm -f *.exe

コンパイル

$ make
fsharpc http_post.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_post.exe
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1