vb.net - Getting remote file size -
what best way remote file size in vb.net? using code:
dim request system.net.webrequest dim response system.net.webresponse dim filesize integer request = net.webrequest.create("http://my-url.com/file.exe") request.method = net.webrequestmethods.http.get response = request.getresponse filesize = response.contentlength
from time doesn't work because giving invalid file size.
putty says: 1.240.214 bytes (valid), vb.net's webrequest
says: 1.246.314 bytes (invalid!)
it looks webrequest using kind of cache... there better way obtain remote file size?
how make head request, this:
dim req system.net.webrequest = system.net.httpwebrequest.create("http://my-url.com/file.exe") req.method = "head" using resp system.net.webresponse = req.getresponse() dim contentlength integer if integer.tryparse(resp.headers.[get]("content-length"), contentlength) ' use contentlength variable here end if end using
does give same result putty?
Comments
Post a Comment