使用.net WebClient UploadFile时,是否可以在multipart标头中手动设置name
属性?或者还有另一种解决方法吗?
-----------------------8cda1896efcd67f
Content-Disposition: form-data; **name="file"**; filename="Testfile.txt"
Content-Type: application/octet-stream
This is a Testfile.
-----------------------8cda1896efcd67f--
感谢您的任何建议!
答案 0 :(得分:0)
您可以通过以下方式使用MultipartFormDataContent:
MultipartFormDataContent form = new MultipartFormDataContent();
string filename = @"Dir:\Testfile.txt"
, name = "file";
byte[] bytes = System.IO.File.ReadAllBytes(filename);
form.Add(new StringContent(name), "file");
form.Add(new ByteArrayContent(bytes), "File", Path.GetFileName(filename));