我需要使用C#向application / octet流的内容类型发送文件。
我可以像下面这样创建一个HttpWebRequest:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://test.com");
request.Headers.Add("content-type", "application/octet-stream");
//Add file here?
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.Created)
{
Console.WriteLine("YAYA");
}
else
{
Console.WriteLine("OH NO MR BILL!!!!");
}
如何在文件流中添加文件?
答案 0 :(得分:1)
只需获取请求流,然后从源流中复制。
using (var requestStream = request.GetRequestStream())
{
fileStream.CopyTo(requestStream);
}