RestSharp.dll というライブラリーを使います。
RestSharp.dll へのシンボリックリンクを コンパイル、実行するフォルダー内に作成します。
http_post.cs
// --------------------------------------------------------------------
/*
http_post.cs
Mar/08/2018
*/
// --------------------------------------------------------------------
using System;
using System.IO;
using RestSharp;
// --------------------------------------------------------------------
class http_post
{
// --------------------------------------------------------------------
static void Main (string[] args)
{
Console.WriteLine ("*** 開始 ***");
const string host_in = "https://httpbin.org";
const string user = "jiro";
const string password = "123456";
var client = new RestClient(host_in);
var request = new RestRequest("/post", Method.POST);
request.AddParameter("user", user);
request.AddParameter("password", password);
IRestResponse response = client.Execute(request);
var content = response.Content;
Console.WriteLine (response);
Console.WriteLine (content);
Console.WriteLine ("*** 終了 ***");
}
// --------------------------------------------------------------------
}
// --------------------------------------------------------------------
Makefile
http_post.exe : http_post.cs
mcs http_post.cs -r:RestSharp.dll
clean:
rm -f *.exe
実行コマンド
mono ./http_post.exe
次のバージョンで確認しました。
$ mono --version
Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3.2 Wed Jun 30 05:34:49 UTC 2021)
Get の例はこちら
Mono: C# の http クライアントの使い方 (Get)