使用 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 (将#修改为@)