我已经成功测试了邮递员。 我想知道为什么我的 C# 总是出错。
这是我的程序
using (var httpClient = new HttpClient())
{
using (var formData = new MultipartFormDataContent())
{
httpClient.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", accessToken);
byte[] fileBytes = File.ReadAllBytes(filePath);
var fileContent = new ByteArrayContent(fileBytes);
formData.Add(fileContent, "file", Path.GetFileName(filePath));
formData.Add(new StringContent("db_backup_archive_file"), "key");
HttpResponseMessage response = await httpClient.PostAsync(url, formData);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("File uploaded successfully.");
}
else
{
Console.WriteLine($"Failed to upload file. Status code:
{response.StatusCode}");
}
}
}
上传文件失败。状态代码:BadRequest