HttpClient and MultipartFormDataContent = upload File an Str



起初对不起我的英语真的很糟糕:-(

我从两天开始就有问题。我将上传一个文件到 https://www.share-online.biz/uploadapi api。但它不起作用。我用 C# 编写了这段代码:

FileInfo fileinfo = new FileInfo(DateiPfad);
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
byte[] file = FileToArray(DateiPfad);
form.Add(new ByteArrayContent(file, 0, file.Length), "fn", "test2.rar");
form.Add(new StringContent(Benutzer), "username");
form.Add(new StringContent(Passwort), "password");
form.Add(new StringContent(sessionname), "upload_session");
form.Add(new StringContent("1"), "chunk_no");
form.Add(new StringContent("1"), "chunk_number");
form.Add(new StringContent(Convert.ToString(file.Length)), "filesize");
form.Add(new StringContent("1"), "finalize");
var response = httpClient.PostAsync(server, form).Result;
httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;
File.WriteAllText("out.txt", sd);
MessageBox.Show("Server: " + sd);

我收到这个请求:

*** EXCEPTION session creation/reuse failed - 09-30-2018, 1:09 pm ***

服务器,会话,密码和用户名来自另一个功能并且工作正常。

有人可以帮我吗?

对于这种类型的工作,我使用Tiny.RestClient。 https://github.com/jgiacomini/Tiny.RestClient

它使构建多个内容变得更加容易。

另一个问题:您确定必须将用户名和密码作为内容发送吗?

相关内容

最新更新