public function downloaddata( byval address as string ) as byte() 接受一個參數,address是從中下載數據的 uri。注意返回的是一個字節數組,我在以前的文章中提到過很多次,我們可以很簡單的轉換為我們需要的格式。 看一個代碼: dim wc as new system.net.webclient() ‘跟網絡相關的類一般都在system.net下 dim html as string = encoding.ascii.getstring(wc.downloaddata("http:www.csdn.net")) debug.writeline(html) 你就會得到很長的一個string,實際上就是csdn第一頁的源代碼。
2.
downloadfile
從具有指定 uri 的資源將數據下載到本地文件
public sub downloadfile( byval address as string, byval filename as string ) address :從中下載數據的 uri。
filename :要接收數據的本地文件的名稱。
使用也很簡單: dim wc as new system.net.webclient() wc.downloadfile("http://www.csdn.net/images/ad/vsnet_120.gif","c:/test.gif") 成功運行后,本地機的c:/會多出一個小圖片,就是vs.net 4cd的廣告。
3. openread
為從具有指定 uri 的資源下載的數據打開一個可讀的流。
public function openread(byval address as string ) as stream
dim mywebclient as new system.net.webclient() dim uristring as string="http://www.csdn.net" console.writeline("accessing {0} ...", uristring) dim mystream as stream = mywebclient.openread(uristring) console.writeline(controlchars.cr + "displaying data :" + controlchars.cr) dim sr as new streamreader(mystream) console.writeline(sr.readtoend()) mystream.close()