所以我有一个 asp.net 应用程序,它在 GET 请求上写入一个字节数组,我试图在 C# 应用程序中接收该字节数组。但是当我尝试下载它时,我似乎只收到了标题。(总增益)
我不是最擅长解释,但我希望代码能让它更清晰。
ASP.NET 代码:
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new StreamContent(new FileStream("D:\\Temp\\uLockStub.dll", FileMode.Open));
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return resp;
C#代码:
var httpReq = (HttpWebRequest)
WebRequest.Create(string.Format("http://localhost:48976/login/login?user={0}&password={1}&hwid={2}",
username, Helper.GetMd5Hash(password), uid));
var resp = httpReq.GetResponse();
var data = resp.GetResponseStream();
var buff = new byte[1024];
var totalBuff = new List<byte>();
var read = 0;
while ((read = data.Read(buff, 0, buff.Length)) > 0)
{
var tmpBuff = new byte[read];
Buffer.BlockCopy(buff, 0, tmpBuff, 0, read);
totalBuff.AddRange(tmpBuff);
}
我究竟做错了什么?
提前致谢!