我想知道如何使用 HttpWebRequest 和 HttpWebResponse 读取持久连接。问题似乎是 GetResponseStream() 函数在返回之前等待服务器连接关闭。
是否有另一种简单的方法来读取彗星连接?不起作用的例子。
// get the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill our buffer
count = resStream.Read(buf, 0, buf.Length);
// as long as we read something we want to print it
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
Debug.Write(tempString);
}
}
while (true); // any more data to read?