Is it possible to manually set the name
attribute in the multipart header when using .net WebClient UploadFile? Or is there another way to get this solved?
-----------------------8cda1896efcd67f
Content-Disposition: form-data; **name="file"**; 开发者_C百科filename="Testfile.txt"
Content-Type: application/octet-stream
This is a Testfile.
-----------------------8cda1896efcd67f--
Thanks for any suggestions!
You can use the MultipartFormDataContent in the following way:
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));
精彩评论