初始化
This commit is contained in:
53
FutureMailAPI/TestRegister.cs
Normal file
53
FutureMailAPI/TestRegister.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class TestRegisterProgram
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
// 生成随机用户名
|
||||
var random = new Random();
|
||||
var username = $"testuser{random.Next(1000, 9999)}";
|
||||
var email = $"{username}@example.com";
|
||||
|
||||
Console.WriteLine($"尝试注册用户: {username}, 邮箱: {email}");
|
||||
|
||||
// 创建注册请求
|
||||
var registerData = new
|
||||
{
|
||||
Username = username,
|
||||
Email = email,
|
||||
Password = "password123"
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(registerData);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
try
|
||||
{
|
||||
// 发送注册请求
|
||||
var response = await client.PostAsync("http://localhost:5001/api/v1/auth/register", content);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"注册成功! 响应内容: {responseContent}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"注册失败! 状态码: {response.StatusCode}");
|
||||
Console.WriteLine($"错误内容: {errorContent}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"发生异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user