LoginSignup
1
5

More than 1 year has passed since last update.

Mono: C# の http クライアントMの使い方 (Post)

Last updated at Posted at 2018-03-08

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)

1
5
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
5