本文整理汇总了VB.NET中System.Net.WebException.WebException构造函数的典型用法代码示例。如果您正苦于以下问题:VB.NET WebException构造函数的具体用法?VB.NET WebException怎么用?VB.NET WebException使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。
在下文中一共展示了WebException构造函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Socket
Try
' A 'Socket' object has been created.
Dim httpSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
' which leads to the 'SocketException' exception.
Dim hostEntry As IPHostEntry = Dns.Resolve("http://www.contoso.com")
Dim serverAddress As IPAddress = hostEntry.AddressList(0)
Dim endPoint As New IPEndPoint(serverAddress, 80)
httpSocket.Connect(endPoint)
Console.WriteLine("Connection created successfully")
httpSocket.Close()
Catch e As SocketException
Dim exp As [String] = e.Message
' Throw the WebException with no parameters.
Throw New WebException()
End Try
示例2: Socket
Try
' A 'Socket' object has been created.
Dim httpSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
Dim serverAddress As IPAddress = hostEntry.AddressList(0)
Dim endPoint As New IPEndPoint(serverAddress, 80)
httpSocket.Connect(endPoint)
Console.WriteLine("Connection created successfully")
httpSocket.Close()
Catch e As SocketException
Console.WriteLine((ControlChars.Cr + "Exception thrown." + ControlChars.Cr + "The Original Message is: " + e.Message))
' Throw the 'WebException' object with a message string specific to the situation.
Throw New WebException("Unable to locate the Server with 'www.contoso.com' Uri.")
End Try
示例3: Socket
Try
' A 'Socket' object has been created.
Dim httpSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
Dim serverAddress As IPAddress = hostEntry.AddressList(0)
Dim endPoint As New IPEndPoint(serverAddress, 80)
httpSocket.Connect(endPoint)
Console.WriteLine("Connection created successfully")
httpSocket.Close()
Catch e As SocketException
Console.WriteLine((ControlChars.Cr + "Exception thrown." + ControlChars.Cr + "The Original Message is: " + e.Message))
' Throw the 'WebException' object with a message string and message status specific to the situation.
Throw New WebException("Unable to locate the Server with 'www.contoso.com' Uri.", WebExceptionStatus.NameResolutionFailure)
End Try
示例4: Socket
Try
' A 'Socket' object has been created.
Dim httpSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
Dim serverAddress As IPAddress = hostEntry.AddressList(0)
Dim endPoint As New IPEndPoint(serverAddress, 80)
httpSocket.Connect(endPoint)
Console.WriteLine("Connection created successfully")
httpSocket.Close()
Catch e As SocketException
Console.WriteLine((ControlChars.Cr + "Exception thrown." + ControlChars.Cr + "The Original Message is: " + e.Message))
' Throw the 'WebException' object with a message string specific to the situation.
' and the 'InnerException' which actually lead to this exception.
Throw New WebException("Unable to locate the Server with 'www.contoso.com' Uri.", e)
End Try
示例5: recvBytes
' Send the data.
Dim ASCII As Encoding = Encoding.ASCII
Dim requestPage As String = "GET /nhjj.htm HTTP/1.1" + ControlChars.Lf + ControlChars.Cr + "Host: " + connectUri + ControlChars.Lf + ControlChars.Cr + "Connection: Close" + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr
Dim byteGet As [Byte]() = ASCII.GetBytes(requestPage)
Dim recvBytes(256) As [Byte]
' Create an 'IPEndPoint' object.
Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
Dim serverAddress As IPAddress = hostEntry.AddressList(0)
Dim endPoint As New IPEndPoint(serverAddress, 80)
' Create a 'Socket' object for sending data.
Dim connectSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' Connect to host using 'IPEndPoint' object.
connectSocket.Connect(endPoint)
' Sent the 'requestPage' text to the host.
connectSocket.Send(byteGet, byteGet.Length, 0)
' Receive the information sent by the server.
Dim bytesReceived As Int32 = connectSocket.Receive(recvBytes, recvBytes.Length, 0)
Dim headerString As [String] = ASCII.GetString(recvBytes, 0, bytesReceived)
' Check whether 'status 404' is there or not in the information sent by server.
If headerString.IndexOf("404") <> False Then
bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0)
Dim memoryStream As New MemoryStream(recvBytes)
getStream = CType(memoryStream, Stream)
' Create a 'WebResponse' object.
Dim myWebResponse As WebResponse = CType(New HttpConnect(getStream), WebResponse)
Dim myException As New Exception("File Not found")
' Throw the 'WebException' object with a message string, message status,InnerException and WebResponse.
Throw New WebException("The Requested page is not found.", myException, WebExceptionStatus.ProtocolError, myWebResponse)
End If
connectSocket.Close()