【发布时间】:2023-01-08 05:20:14
【问题描述】:
我想通过 RestSharp 将文件发布到 API,但是 Method.Post 遇到错误无法从“RestSharp.Method”转换为“字符串”?,Method.POST 的错误是“方法”不包含“POST”的定义?
using RestSharp;
using System;
using System.Net;
using System.Net.Http;
namespace UploadToAzure
{
class Program
{
static void Main()
{
var client = new RestClient("http://localhost:7071/api/Function1");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddFile("File", "/D:/sample Files/audio0001.mp3");
IRestResponse response = (IRestResponse)client.Execute(request);
Console.WriteLine(response.Content);
}
}
}
感谢您的回答!
【问题讨论】:
-
RestRequest可能将一个作为 URL 的字符串作为参数,但您给它一个Method。查看文档和示例以了解如何使用RestRequest -
RestSharp 是什么版本?
-
我怎样才能找到它?