0
我有以下功能什麼時候WebRequest.GetResponse()設置連接到「保持活躍」 C#
private byte[] Function(string url)
{
HttpWebRequest webRequest= (HttpWebRequest)WebRequest.Create(url);
webRequest.AddRange(0, 200);
webRequest.Method = "GET";
webRequest.KeepAlive = true;
byte[] buffer = new byte[200];
using (var webResponse = webRequest.GetResponse())
using (Stream webResponseStreem = webResponse.GetResponseStream())
{
webResponseStreem.Read(buffer, 0, 200);
}
return buffer;
}
,我把它從我的應用程序的不同部分。有時我得到的結果不是我所期望的。我注意到有時撥打電話webRequest.GetResponse()
設置webRequest.Connection
到"Keep-Alive"
,有時不會。它依賴於什麼?