成員 | 類(lèi)型 | 描述 |
baseuri | 屬性 | 當(dāng)前的url地址 |
downloaddata | 方法 | 從一個(gè)uri下載數(shù)據(jù),以字節(jié)數(shù)組的形式返回 |
downloadfile | 方法 | 從一個(gè)uri下載數(shù)據(jù),保存為本地文件 |
openread | 方法 | 以流的形式打開(kāi)并執(zhí)行讀操作 |
openwrite | 方法 | 打開(kāi)一個(gè)流用于向uri寫(xiě)數(shù)據(jù) |
uploaddata | 方法 | 向uri上傳數(shù)據(jù) |
uploadfile | 方法 | 把一個(gè)本地文件上載到制定uri |
uploadvalues | 方法 | namevaluecollection 發(fā)送到資源并返回包含任何響應(yīng)的字節(jié)數(shù)組 |
public function downloaddata( byval address as string ) as byte()
接受一個(gè)參數(shù),address是從中下載數(shù)據(jù)的 uri。注意返回的是一個(gè)字節(jié)數(shù)組,我在以前的文章中提到過(guò)很多次,我們可以很簡(jiǎn)單的轉(zhuǎn)換為我們需要的格式。
看一個(gè)代碼:
dim wc as new system.net.webclient() ‘跟網(wǎng)絡(luò)相關(guān)的類(lèi)一般都在system.net下
dim html as string = encoding.ascii.getstring(wc.downloaddata("http:www.csdn.net"))debug.writeline(html)
public sub downloadfile( byval address as string, byval filename as string )
使用也很簡(jiǎn)單:
dim wc as new system.net.webclient()
wc.downloadfile("/xrssfile/2006-12/26/2006122602354452.gif")成功運(yùn)行后,本地機(jī)的c:/會(huì)多出一個(gè)小圖片,就是vs.net 4cd的廣告。
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()
新聞熱點(diǎn)
疑難解答
圖片精選