ファイルをチャンクで HttpHandler に送信しようとしていますが、HttpContext でリクエストを受信すると、inputStream は空です。
したがって、a: 送信中に HttpWebRequest が有効かどうかわかりません。b: 受信中に 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);
}