微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 multipart/form-data 上传文件时出现 RestSharp 错误

如何解决使用 multipart/form-data 上传文件时出现 RestSharp 错误

您好 尝试将文件上传到 Octoprint 但未成功。以下是restSharp响应中的错误异常。

7645753 上传 完成以下回复

System.Net.WebException:操作超时。

在 System.Net.HttpWebRequest.GetResponse()

在 RestSharp.Http.g__GetRawResponse|181_1(WebRequest 请求)

在 RestSharp.Http.ExecuteRequest(String httpMethod,Action`1 prepareRequest)**

以下是我正在执行的代码

   public static void getAPI()
    {
    string authToken = "Token Removed";
            var client = new RestClient("http://192.168.1.222:5000/api");
            string path = @"C:\Downloads\output.gcode";
            string readText = File.ReadAllText(path);
            var leng = readText.Length;
            Console.WriteLine(leng.ToString());  //Checking if it had read the complete file


            CurrUser.AddHeader("X-Api-Key",authToken);

            var home3d = new RestRequest("files/local",DataFormat.Json);
            home3d.AddHeader("Content-Type","multipart/form-data; boundary=-----------WebKitFormBoundary");  //Header Def for File
            home3d.AddHeader("X-Api-Key",authToken);
            home3d.AddHeader("Content-Length",leng.ToString());
            home3d.AddParameter("file","-----------WebKitFormBoundary" + readText+ "-----------WebKitFormBoundary");
            home3d.AddParameter("filename","output.gcode");
            home3d.AddParameter("select","true");
            Console.WriteLine("Uploading");
            var response = client.Post(home3d);
            Console.WriteLine("Finished with following response");
            Console.WriteLine(response.ErrorException); //writing response to console

}

我尝试上传文件的服务器是 ubuntu,文件夹权限设置为 777。

等待成员的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。