using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
static async Task Main(string[] args)
var result = await LoginAsync(new LoginRequestDto()
Console.WriteLine(result);
private static async Task<string> LoginAsync(LoginRequestDto loginRequestDto)
using (HttpClient client = new HttpClient())
string endPoint = $"https://localhost:5001/api/PassParameter/FromForm";
HttpResponseMessage response = null;
#region 使用 MultipartFormDataContent (form-data) 產生要 Post 的資料
Dictionary<string, string> formDataDictionary = new Dictionary<string, string>()
{nameof(loginRequestDto.Account), loginRequestDto.Account.ToString() },
{nameof(loginRequestDto.Password), loginRequestDto.Password },
using (var fooContent = new MultipartFormDataContent())
foreach (var keyValuePair in formDataDictionary)
fooContent.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
response = await client.PostAsync(endPoint, fooContent);
result = await response.Content.ReadAsStringAsync();
#region 呼叫 Web API 會用到的類別
public class LoginRequestDto
public string Account { get; set; }
public string Password { get; set; }