0

我有一个小 C# API,到目前为止,它一直在做 GET 并且运行良好,但我想添加客户端能够通过 POST 上传文件的能力,还没有网络表单或任何附加到 API 的东西所以现在我只是使用 Fiddler 通过 POST 上传文件

public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
    { ..... }

当我调试时,我看到 postdata 包含 Fiddler 发送的整个正文,我假设它是 base 64。

来自 Fiddler2 的请求正文:

---------------------------acebdf13572468
Content-Disposition: form-data; name="fieldNameHere"; filename="sample_iTunes.mov"
Content-Type: video/quicktime

<@INCLUDE *C:\Users\Public\Videos\Sample Videos\sample_iTunes.mov*@>
---------------------------acebdf13572468--

我可以看到 postdata =

"---------------------------acebdf13572468\r\nContent-Disposition: form-data; name=\"fieldNameHere\"; filename=\"sample_iTunes.mov\"\r\nContent-Type: video/quicktime\r\n\r\n\0\0\0 ftypqt   \0qt  \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\bwide\01�4mdat\0\0�\0\0��\0\0\0\0\0 \0Ĉ�\f�\n1\0\0�3ivx@�\0\0�����x�o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6���o�m����6�(a lot more stuff)----acebdf13572468--\r\n" 

有没有从这里获取文件的正确方法?或者我是否需要尝试对文件输出进行子串化(从 quicktime 结束 \r\n\r\n 到结束 ----acebdf13572468--\r\n),然后执行 Bytes[] file = Convert.从Base64字符串?

谢谢

4

0 回答 0