c# downloading webpage. improved proceed needed, cpu use high
i'm perplexing square formula operative small better. i think it's loop reading byte during time. i couldn't another proceed doing gzip decompression. implementing streamreader
fine, nonetheless advantage twine i can't pass decompression stream.
is there improved way?
byte[] bufffer = null;
list<byte> resourcebytes = new list<byte>();
int bytevalue = 0;
webresource apparatus = new webresource();
httpwebresponse webresponse = null;
try {
httpwebrequest webrequest = (httpwebrequest)webrequest.create(resourceuri);
webrequest.headers.add(httprequestheader.acceptencoding, "gzip,deflate");
webrequest.headers.add(httprequestheader.acceptcharset, "iso-8859-1,utf-8;q=0.7,*;q=0.7");
webrequest.useragent = agent;
webrequest.accept = "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1";
webrequest.credentials = credentialcache.defaultcredentials;
webrequest.referer = resourceuri.originalstring;
webrequest.timeout = 5000;
webresponse = (httpwebresponse)webrequest.getresponse();
tide webstream = webresponse.getresponsestream();
(!string.isnullorempty(webresponse.contentencoding)) {
(webresponse.contentencoding.tolower().contains("gzip")) {
webstream = new gzipstream(webstream, compressionmode.decompress);
}
else (webresponse.contentencoding.tolower().contains("deflate")) {
webstream = new deflatestream(webstream, compressionmode.decompress);
}
}
{
bytevalue = webstream.readbyte();
(bytevalue != -1) {
resourcebytes.add((byte)bytevalue);
}
} while (bytevalue != -1);
//free adult resources
webstream.close();
webresponse.close();
bufffer = resourcebytes.toarray();
Comments
Post a Comment