How to Clone HttpWebRequest?
I want to set some properties o开发者_开发技巧f an HttpWebRequest
and then download some files asynchronously. However, I need one copy of HttpWebRequest
for each download, so how can I clone it so that I don't have to copy each property "by hand"?
HttpWebRequest does not support serialization or cloning, thus you have to implement your own mechanism to save/copy it. You can use serialized (or clonable) derived class or some wrapper for this task.
Create your own class to hold the properties you're interested in. That class can implement IClonable
if necessary. In any case, use these properties to initialize each new instance of HttpWebRequest
.
you need to be careful when creating a number of connection using HttpWebRequest. http://arnosoftwaredev.blogspot.com/2006/09/net-20-httpwebrequestkeepalive-and.html As it is not serializable you can create a wrapper class
精彩评论