DownloadStringAsync
will create a single giant string containing the entire response.
If you call that for lots of big responses, you will run out of memory.
Instead, you should use HttpWebRequest
directly.
Its GetResponse()
(or BeginGetResponse()
) method gives you a stream that allows you to read the response directly from the server without buffering it in memory.
If you still want asyncrony, you should move the .Net 4.5, which adds the easier-to-use GetResponseAsync()
method (as opposed to the old APM-based BeginGetResponse()
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…