cURL to C# 変換ツール (.NET HttpClient, RestSharp & Flurl) 開発者ガイド
コマンドラインの cURL リクエストを、.NET HttpClient、RestSharp、Flurl.Http を用いた実用的な C# コードへ高精度に変換。非同期処理や接続プーリングのベストプラクティスに対応。
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.openai.com/v1/chat/completions");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "sk-proj-mockToken998877665544332211");
var jsonPayload = """
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a professional C# and .NET full-stack architect."
},
{
"role": "user",
"content": "Demonstrate modern HttpClient and RestSharp best practices."
}
],
"temperature": 0.7,
"max_tokens": 1000
}
""";
request.Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
try
{
using var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException ex)
{
Console.WriteLine($"[HTTP Request Failed] {ex.StatusCode}: {ex.Message}");
}100% クライアントサイド変換
ブラウザ内だけでcURL構文解析およびC#コード生成を完全完結。外部サーバーへの通信は一切ありません。
.NET 8/9 と多彩なライブラリ
モダンなHttpClient、RestSharp v107+、Flurl.Http、IHttpClientFactory DIパターンに対応。
認証・フラグの完全再現
Bearerトークン、Basic認証、カスタムヘッダー、マルチパートFormData、タイムアウト、SSLスキップに対応。