WebException WebException WebException WebException Constructors

Definizione

Overload

WebException() WebException() WebException()

Inizializza una nuova istanza della classe WebException.Initializes a new instance of the WebException class.

WebException(String) WebException(String) WebException(String) WebException(String)

Inizializza una nuova istanza della classe WebException con il messaggio di errore specificato.Initializes a new instance of the WebException class with the specified error message.

WebException(SerializationInfo, StreamingContext) WebException(SerializationInfo, StreamingContext) WebException(SerializationInfo, StreamingContext)

Inizializza una nuova istanza della classe WebException dalle istanze di SerializationInfo e StreamingContext specificate.Initializes a new instance of the WebException class from the specified SerializationInfo and StreamingContext instances.

WebException(String, WebExceptionStatus) WebException(String, WebExceptionStatus) WebException(String, WebExceptionStatus) WebException(String, WebExceptionStatus)

Inizializza una nuova istanza della classe WebException con il messaggio di errore e lo stato specificati.Initializes a new instance of the WebException class with the specified error message and status.

WebException(String, Exception) WebException(String, Exception) WebException(String, Exception) WebException(String, Exception)

Inizializza una nuova istanza della classe WebException con il messaggio di errore e l'eccezione annidata specificati.Initializes a new instance of the WebException class with the specified error message and nested exception.

WebException(String, Exception, WebExceptionStatus, WebResponse) WebException(String, Exception, WebExceptionStatus, WebResponse) WebException(String, Exception, WebExceptionStatus, WebResponse) WebException(String, Exception, WebExceptionStatus, WebResponse)

Inizializza una nuova istanza della classe WebException con il messaggio di errore, l'eccezione annidata, lo stato e la risposta specificati.Initializes a new instance of the WebException class with the specified error message, nested exception, status, and response.

WebException() WebException() WebException()

Inizializza una nuova istanza della classe WebException.Initializes a new instance of the WebException class.

public:
 WebException();
public WebException ();
Public Sub New ()

Esempi

Nell'esempio seguente viene generata un' WebExceptionimpostazione predefinita.The following example throws a default WebException.

try
{
   // A 'Socket' object has been created.
   Socket^ httpSocket = gcnew Socket( AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp );
   

   // The IPaddress of the unknown uri is resolved using the 'Dns::Resolve' method.

   IPHostEntry^ hostEntry = Dns::Resolve( "http://www.contoso.com" );

   IPAddress^ serverAddress = hostEntry->AddressList[ 0 ];
   IPEndPoint^ endPoint = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   String^ exp = e->Message;
   // Throw the WebException with no parameters.
   throw gcnew WebException;
}

 try   
 {
     // A 'Socket' object has been created.
     Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

     // The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method. 
     
     IPHostEntry hostEntry = Dns.Resolve("http://www.contoso.com");

     IPAddress serverAddress = hostEntry.AddressList[0];
     IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
     httpSocket.Connect(endPoint);
     Console.WriteLine("Connection created successfully");
     httpSocket.Close();
  }
catch(SocketException e)
  {
  String exp = e.Message;	
  // Throw the WebException with no parameters.
     throw new WebException();
  }
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

Commenti

Il costruttore senza parametri Inizializza una nuova istanza della WebException classe.The parameterless constructor initializes a new instance of the WebException class. La Message proprietà viene inizializzata su un messaggio fornito dal sistema in cui viene descritto l'errore.The Message property is initialized to a system-supplied message that describes the error. Questo messaggio prende in considerazione le impostazioni cultura correnti del sistema.This message takes into account the current system culture. Le InnerException proprietà Response e vengono inizializzate nullin.The InnerException and Response properties are initialized to null. La proprietà Status viene inizializzata su RequestCanceled.The Status property is initialized to RequestCanceled.

WebException(String) WebException(String) WebException(String) WebException(String)

Inizializza una nuova istanza della classe WebException con il messaggio di errore specificato.Initializes a new instance of the WebException class with the specified error message.

public:
 WebException(System::String ^ message);
public WebException (string message);
new System.Net.WebException : string -> System.Net.WebException
Public Sub New (message As String)

Parametri

message
String String String String

Il testo del messaggio di errore,The text of the error message.

Esempi

Nell'esempio seguente viene generata WebException un'eccezione specificando un messaggio di errore.The following example throws a WebException by specifying an error message.

try
{
   // A 'Socket' object has been created.
   Socket^ httpSocket = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp );
   
   // The IPaddress of the unknown uri is resolved using the 'Dns::Resolve' method.
   IPHostEntry^ hostEntry = Dns::Resolve( connectUri );

   IPAddress^ serverAddress = hostEntry->AddressList[ 0 ];
   IPEndPoint^ endPoint = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "\nException thrown.\nThe Original Message is: {0}", e->Message );
   
   // Throw the 'WebException' object with a message string specific to the situation.
   throw gcnew WebException( "Unable to locate the Server with 'www.contoso.com' Uri." );
}
 try
{
     // A 'Socket' object has been created.
     Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

     // The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method. 
     IPHostEntry hostEntry = Dns.Resolve(connectUri);

     IPAddress serverAddress = hostEntry.AddressList[0];
     IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
     httpSocket.Connect(endPoint);
     Console.WriteLine("Connection created successfully");
     httpSocket.Close();
  }
catch(SocketException e)
  {		     
     Console.WriteLine("\nException thrown.\nThe 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.");
  }

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

Commenti

L' WebException istanza viene inizializzata con Message la proprietà impostata sul valore di message.The WebException instance is initialized with the Message property set to the value of message. Se message Message è null, la proprietà viene inizializzata su un messaggio fornito dal sistema.If message is null, the Message property is initialized to a system-supplied message. Le InnerException proprietà Response e vengono inizializzate nullin.The InnerException and Response properties are initialized to null. La proprietà Status viene inizializzata su RequestCanceled.The Status property is initialized to RequestCanceled.

Vedi anche

WebException(SerializationInfo, StreamingContext) WebException(SerializationInfo, StreamingContext) WebException(SerializationInfo, StreamingContext)

Inizializza una nuova istanza della classe WebException dalle istanze di SerializationInfo e StreamingContext specificate.Initializes a new instance of the WebException class from the specified SerializationInfo and StreamingContext instances.

protected:
 WebException(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
protected WebException (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
new System.Net.WebException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebException

Parametri

serializationInfo
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

Oggetto SerializationInfo contenente le informazioni necessarie per serializzare il nuovo oggetto WebException.A SerializationInfo that contains the information required to serialize the new WebException.

streamingContext
StreamingContext StreamingContext StreamingContext StreamingContext

Oggetto StreamingContext contenente l'origine del flusso serializzato associato alla nuova istanza di WebException.A StreamingContext that contains the source of the serialized stream that is associated with the new WebException.

Commenti

Questo costruttore implementa l' ISerializable interfaccia per la WebException classe.This constructor implements the ISerializable interface for the WebException class.

Vedi anche

WebException(String, WebExceptionStatus) WebException(String, WebExceptionStatus) WebException(String, WebExceptionStatus) WebException(String, WebExceptionStatus)

Inizializza una nuova istanza della classe WebException con il messaggio di errore e lo stato specificati.Initializes a new instance of the WebException class with the specified error message and status.

public:
 WebException(System::String ^ message, System::Net::WebExceptionStatus status);
public WebException (string message, System.Net.WebExceptionStatus status);
new System.Net.WebException : string * System.Net.WebExceptionStatus -> System.Net.WebException
Public Sub New (message As String, status As WebExceptionStatus)

Parametri

message
String String String String

Il testo del messaggio di errore,The text of the error message.

Esempi

Nell'esempio seguente viene generata WebException un'eccezione specificando un messaggio di WebExceptionStatuserrore e un oggetto.The following example throws a WebException by specifying an error message and a WebExceptionStatus.

try
{
   // A 'Socket' object has been created.
   Socket^ httpSocket = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp );
   
   // The IPaddress of the unknown uri is resolved using the 'Dns::Resolve' method.

   IPHostEntry^ hostEntry = Dns::Resolve( "http://www.contoso.com" );

   IPAddress^ serverAddress = hostEntry->AddressList[ 0 ];
   IPEndPoint^ endPoint = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "\nException thrown.\nThe Original Message is: {0}", e->Message );
   // Throw the 'WebException' object with a message string and message status specific to the situation.
   throw gcnew WebException( "Unable to locate the Server with 'www.contoso.com' Uri.", WebExceptionStatus::NameResolutionFailure );
}

 try
{
       // A 'Socket' object has been created.
       Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

      // The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method. 
  
      IPHostEntry hostEntry = Dns.Resolve("http://www.contoso.com");

      IPAddress serverAddress = hostEntry.AddressList[0];
      IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
      httpSocket.Connect(endPoint);
      Console.WriteLine("Connection created successfully");
      httpSocket.Close();

   }
catch(SocketException e)
  {
      Console.WriteLine("\nException thrown.\nThe 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);
  }

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

Commenti

L' WebException istanza viene inizializzata con Message la proprietà impostata sul valore di message e la Status proprietà impostata sul valore di status.The WebException instance is initialized with the Message property set to the value of message and the Status property set to the value of status. Se message Message è null, la proprietà viene inizializzata su un messaggio fornito dal sistema.If message is null, the Message property is initialized to a system-supplied message. Le InnerException proprietà Response e vengono inizializzate nullin.The InnerException and Response properties are initialized to null.

WebException(String, Exception) WebException(String, Exception) WebException(String, Exception) WebException(String, Exception)

Inizializza una nuova istanza della classe WebException con il messaggio di errore e l'eccezione annidata specificati.Initializes a new instance of the WebException class with the specified error message and nested exception.

public:
 WebException(System::String ^ message, Exception ^ innerException);
public WebException (string message, Exception innerException);
new System.Net.WebException : string * Exception -> System.Net.WebException
Public Sub New (message As String, innerException As Exception)

Parametri

message
String String String String

Il testo del messaggio di errore,The text of the error message.

inner
Exception Exception Exception Exception

Un'eccezione annidata.A nested exception.

Esempi

Nell'esempio seguente viene generata WebException un'eccezione specificando un messaggio di errore e un'eccezione annidata.The following example throws a WebException by specifying an error message and nested exception.

try
{
   // A 'Socket' object has been created.
   Socket^ httpSocket = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp );
   
   // The IPaddress of the unknown uri is resolved using the 'Dns::Resolve' method.

   IPHostEntry^ hostEntry = Dns::Resolve( connectUri );

   IPAddress^ serverAddress = hostEntry->AddressList[ 0 ];
   IPEndPoint^ endPoint = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "\nException thrown.\nThe Original Message is: {0}", e->Message );
   //  Throw the 'WebException' object with a message string specific to the situation;
   //  and the 'InnerException' that actually led to this exception.
   throw gcnew WebException( "Unable to locate the Server with 'www.contoso.com' Uri.", e );
}

   try
   {
          // A 'Socket' object has been created.
          Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

          // The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method. 
       
          IPHostEntry hostEntry = Dns.Resolve(connectUri);

          IPAddress serverAddress = hostEntry.AddressList[0];
          IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
          httpSocket.Connect(endPoint);
          Console.WriteLine("Connection created successfully");
          httpSocket.Close();		 
    }
  catch(SocketException e)
{ 
       Console.WriteLine("\nException thrown.\nThe 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);
    }


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

Commenti

L' WebException istanza viene inizializzata con Message la proprietà impostata sul valore di message e la InnerException proprietà impostata sul valore di innerException.The WebException instance is initialized with the Message property set to the value of message and the InnerException property set to the value of innerException. Se message Message è null, la proprietà viene inizializzata su un messaggio fornito dal sistema.If message is null, the Message property is initialized to a system-supplied message. Le InnerException proprietà Response e vengono inizializzate nullin.The InnerException and Response properties are initialized to null. La proprietà Status viene inizializzata su RequestCanceled.The Status property is initialized to RequestCanceled.

Vedi anche

WebException(String, Exception, WebExceptionStatus, WebResponse) WebException(String, Exception, WebExceptionStatus, WebResponse) WebException(String, Exception, WebExceptionStatus, WebResponse) WebException(String, Exception, WebExceptionStatus, WebResponse)

Inizializza una nuova istanza della classe WebException con il messaggio di errore, l'eccezione annidata, lo stato e la risposta specificati.Initializes a new instance of the WebException class with the specified error message, nested exception, status, and response.

public:
 WebException(System::String ^ message, Exception ^ innerException, System::Net::WebExceptionStatus status, System::Net::WebResponse ^ response);
public WebException (string message, Exception innerException, System.Net.WebExceptionStatus status, System.Net.WebResponse response);
new System.Net.WebException : string * Exception * System.Net.WebExceptionStatus * System.Net.WebResponse -> System.Net.WebException
Public Sub New (message As String, innerException As Exception, status As WebExceptionStatus, response As WebResponse)

Parametri

message
String String String String

Il testo del messaggio di errore,The text of the error message.

inner
Exception Exception Exception Exception

Un'eccezione annidata.A nested exception.

response
WebResponse WebResponse WebResponse WebResponse

Istanza di WebResponse contenente la risposta dall'host remoto.A WebResponse instance that contains the response from the remote host.

Esempi

Nell'esempio seguente viene generata WebException un'eccezione specificando un messaggio di WebExceptionStatuserrore e un oggetto.The following example throws a WebException by specifying an error message and a WebExceptionStatus.

// Send the data.
Encoding^ ASCII = Encoding::ASCII;
String^ requestPage = String::Concat( "GET /nhjj.htm HTTP/1.1\r\nHost: ", connectUri, "\r\nConnection: Close\r\n\r\n" );
array<Byte>^ byteGet = ASCII->GetBytes( requestPage );
array<Byte>^ recvBytes = gcnew array<Byte>(256);

// Create an 'IPEndPoint' object.

IPHostEntry^ hostEntry = Dns::Resolve( connectUri );
IPAddress^ serverAddress = hostEntry->AddressList[ 0 ];
IPEndPoint^ endPoint = gcnew IPEndPoint( serverAddress,80 );

// Create a 'Socket' object  for sending data.
Socket^ connectSocket = gcnew 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, (SocketFlags)(0) );

// Receive the information sent by the server.
Int32 bytesReceived = connectSocket->Receive( recvBytes, recvBytes->Length, (SocketFlags)(0) );
String^ headerString = ASCII->GetString( recvBytes, 0, bytesReceived );

// Check whether 'status 404' is there or not in the information sent by server.
if ( headerString->IndexOf( "404" ) != -1 )
{
   bytesReceived = connectSocket->Receive( recvBytes, recvBytes->Length, (SocketFlags)(0) );
   MemoryStream^ memoryStream = gcnew MemoryStream( recvBytes );
   getStream = (System::IO::Stream^)(memoryStream);
   
   // Create a 'WebResponse' object
   WebResponse^ myWebResponse = (WebResponse^)(gcnew HttpConnect( getStream ));
   Exception^ myException = gcnew Exception( "File Not found" );

   // Throw the 'WebException' object with a message string, message status, InnerException and WebResponse
   throw gcnew WebException( "The Requested page is not found.",myException,WebExceptionStatus::ProtocolError,myWebResponse );
}

connectSocket->Close();
            // Send the data. 
            Encoding ASCII = Encoding.ASCII;
            string requestPage = "GET /nhjj.htm HTTP/1.1\r\nHost: " + connectUri + "\r\nConnection: Close\r\n\r\n";
            Byte[] byteGet = ASCII.GetBytes(requestPage);
            Byte[] recvBytes = new Byte[256];

            // Create an 'IPEndPoint' object.
       
            IPHostEntry hostEntry = Dns.Resolve(connectUri);
            IPAddress serverAddress = hostEntry.AddressList[0];
            IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
      
            // Create a 'Socket' object  for sending data.
            Socket connectSocket = 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.
            Int32 bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0);
            String headerString = ASCII.GetString(recvBytes, 0, bytesReceived);
           


           
           // Check whether 'status 404' is there or not in the information sent by server.
           if(headerString.IndexOf("404")!=-1)
           {	 
               bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0);
               MemoryStream memoryStream = new MemoryStream(recvBytes);
               getStream = (Stream) memoryStream;
       
               // Create a 'WebResponse' object
               WebResponse myWebResponse = (WebResponse) new HttpConnect(getStream);
               Exception myException = 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);


           }

           connectSocket.Close();	

     ' 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()
     

Commenti

L' WebException istanza viene inizializzata con Message la proprietà impostata sul valore di message, la InnerException proprietà impostata sul valore di innerException, la Status proprietà impostata sul valore di statuse l'oggetto Response proprietà impostata sul valore di response.The WebException instance is initialized with the Message property set to the value of message, the InnerException property set to the value of innerException, the Status property set to the value of status, and the Response property set to the value of response. Se message Message è null, la proprietà viene inizializzata su un messaggio fornito dal sistema.If message is null, the Message property is initialized to a system-supplied message.

Si applica a