首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RestSharp中的POST函数

RestSharp中的POST函数
EN

Stack Overflow用户
提问于 2022-08-25 16:55:36
回答 1查看 144关注 0票数 0

我想通过RestSharp向API发布一个文件,但是Method.Post遇到的错误不能从“RestSharp.Method”转换为“RestSharp.Method?”,而Method.POST的错误是“方法”不包含“POST”的定义。

代码语言:javascript
复制
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);
        }
    }
}

谢谢你的回答!

EN

回答 1

Stack Overflow用户

发布于 2022-08-25 18:58:06

当我将目的地字符串添加到RestRequest并将IRestResponse更改为RestResponse时,就解决了这个问题。此外,纠正文件的路径。

代码语言:javascript
复制
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);
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73491194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档