开发者

How to modify Content-Disposition Header when using .net WebClient FileUpload

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜