LoginSignup
0
4

More than 1 year has passed since last update.

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

Last updated at Posted at 2018-03-08

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

http_get.cs
// --------------------------------------------------------------------
/*
	http_get.cs

						Mar/08/2018
*/
// --------------------------------------------------------------------
using	System;
using	System.IO;
using	RestSharp;
// --------------------------------------------------------------------
class	http_get
{
// --------------------------------------------------------------------
static	void	Main (string[] args)
{
	Console.WriteLine ("*** 開始 ***");

	const string host_in = "https://httpbin.org";

	var client = new RestClient(host_in);

	var request = new RestRequest("/get", Method.GET);

	IRestResponse response = client.Execute(request);

	var content = response.Content;

	Console.WriteLine (response);
	Console.WriteLine (content);

	Console.WriteLine ("*** 終了 ***");
}

// --------------------------------------------------------------------
}

// --------------------------------------------------------------------
Makefile
http_get.exe : http_get.cs
	mcs http_get.cs -r:RestSharp.dll
clean:
	rm -f *.exe

実行コマンド

mono ./http_get.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)
0
4
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
0
4