我想通过RestSharp向API发布一个文件,但是Method.Post遇到的错误不能从“RestSharp.Method”转换为“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);
}
}
}谢谢你的回答!
发布于 2022-08-25 18:58:06
当我将目的地字符串添加到RestRequest并将IRestResponse更改为RestResponse时,就解决了这个问题。此外,纠正文件的路径。
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");
RestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
}
}
}https://stackoverflow.com/questions/73491194
复制相似问题