Imports System.Net.Sockets
Imports System.Net
Imports System.IO
Imports System.Text
Public Class Tester
Public Shared Sub Main
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim respStream As Stream
Dim respStreamReader As StreamReader
Dim strBuff As String = Nothing
Dim cbuffer(256) As Char
Dim byteRead As Integer = 0
Dim index As Integer = 0
Try
Dim httpURL As New System.Uri("http://www.java2java.com")
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
respStream = httpResp.GetResponseStream()
respStreamReader = New StreamReader(respStream, Encoding.UTF8)
byteRead = respStreamReader.Read(cbuffer, 0, 256)
While (byteRead <> 0)
Dim strResp As New [String](cbuffer, 0, byteRead)
Console.WriteLine(strResp)
byteRead = respStreamReader.Read(cbuffer, 0, 256)
End While
respStream.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace.ToString())
End Try
End Sub
End Class
|