我试图将一个chu子的档案寄给一名HttpHandler,但在我收到HttpContext的请求时,投入Stream是空的。
So a: while sending I m not sure if my HttpWebRequest is valid and b: while receiving I m not sure how to retrieve the stream in the HttpContext
任何帮助都受到高度赞赏。
我如何要求客户守则:
private void Post(byte[] bytes)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost:2977/Upload");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.SendChunked = true;
req.Timeout = 400000;
req.ContentLength = bytes.Length;
req.KeepAlive = true;
using (Stream s = req.GetRequestStream())
{
s.Write(bytes, 0, bytes.Length);
s.Close();
}
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
}
这是我如何处理HttpHandler的要求:
public void ProcessRequest(HttpContext context)
{
Stream chunk = context.Request.InputStream; //it s empty!
FileStream output = new FileStream("C:\Temp\myTempFile.tmp", FileMode.Append);
//simple method to append each chunk to the temp file
CopyStream(chunk, output);
}