49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
class ApiTest
|
|
{
|
|
static async Task Main(string[] args)
|
|
{
|
|
using var client = new HttpClient();
|
|
|
|
// 设置请求头
|
|
client.DefaultRequestHeaders.Authorization =
|
|
new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxIiwidW5pcXVlX25hbWUiOiJ0ZXN0dXNlciIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsIm5iZiI6MTc2MDUwOTEwNCwiZXhwIjoxNzYxMTEzOTA0LCJpYXQiOjE3NjA1MDkxMDQsImlzcyI6IkZ1dHVyZU1haWxBUEkiLCJhdWQiOiJGdXR1cmVNYWlsQ2xpZW50In0.122kbPX2GsD1uo2DZNnJ6M7s6AP31bm8arNm770jBG8");
|
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
|
|
// 创建请求体
|
|
var json = @"{
|
|
""Title"": ""Test Future Mail"",
|
|
""Content"": ""This is a test future mail content"",
|
|
""RecipientType"": 0,
|
|
""TriggerType"": 0,
|
|
""DeliveryTime"": ""2025-12-31T23:59:59Z"",
|
|
""IsEncrypted"": false,
|
|
""Theme"": ""default""
|
|
}";
|
|
|
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
try
|
|
{
|
|
// 发送POST请求
|
|
var response = await client.PostAsync("http://localhost:5001/api/v1/mails", content);
|
|
|
|
// 显示响应状态
|
|
Console.WriteLine($"状态码: {response.StatusCode}");
|
|
|
|
// 读取响应内容
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
Console.WriteLine($"响应内容: {responseContent}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"错误: {ex.Message}");
|
|
Console.WriteLine($"详细信息: {ex}");
|
|
}
|
|
}
|
|
} |