WebException 생성자

정의

WebException 클래스의 새 인스턴스를 초기화합니다.

오버로드

WebException()

WebException 클래스의 새 인스턴스를 초기화합니다.

WebException(String)

지정된 오류 메시지를 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

WebException(SerializationInfo, StreamingContext)
사용되지 않음.

지정된 WebExceptionSerializationInfo 인스턴스에서 StreamingContext 클래스의 새 인스턴스를 초기화합니다.

WebException(String, WebExceptionStatus)

지정된 오류 메시지와 상태를 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

WebException(String, Exception)

지정된 오류 메시지와 중첩된 예외를 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

WebException(String, Exception, WebExceptionStatus, WebResponse)

지정된 오류 메시지, 중첩된 예외, 상태 및 응답을 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

WebException()

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

WebException 클래스의 새 인스턴스를 초기화합니다.

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

예제

다음 예제에서는 기본 WebException을 throw합니다.

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

설명

매개 변수가 없는 생성자는 클래스의 WebException 새 instance 초기화합니다. Message 속성은 오류를 설명 하는 시스템 제공 메시지로 초기화 합니다. 이 메시지는 현재 시스템 culture를 고려합니다. 합니다 InnerException 하 고 Response 속성으로 초기화 됩니다 null합니다. Status 속성이 RequestCanceled으로 초기화됩니다.

적용 대상

WebException(String)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지를 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

message
String

오류 메시지 텍스트입니다.

예제

다음 예제에서는 WebException 오류 메시지를 지정하여 을 throw합니다.

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

설명

합니다 WebException 인스턴스가 사용 하 여 초기화 되는 Message 속성의 값으로 설정 message합니다. 하는 경우 message 됩니다 nullMessage 속성은 시스템 제공 메시지로 초기화 합니다. 합니다 InnerException 하 고 Response 속성으로 초기화 됩니다 null합니다. Status 속성이 RequestCanceled으로 초기화됩니다.

추가 정보

적용 대상

WebException(SerializationInfo, StreamingContext)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

주의

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

지정된 WebExceptionSerializationInfo 인스턴스에서 StreamingContext 클래스의 새 인스턴스를 초기화합니다.

protected:
 WebException(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
protected WebException (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
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
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Net.WebException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebException
Protected Sub New (serializationInfo As SerializationInfo, streamingContext As StreamingContext)

매개 변수

serializationInfo
SerializationInfo

WebException을 직렬화하는 데 필요한 정보가 들어 있는 SerializationInfo입니다.

streamingContext
StreamingContext

WebException과 관련된 직렬화된 스트림의 원본이 들어 있는 StreamingContext입니다.

특성

설명

이 생성자는 클래스에 ISerializable 대한 인터페이스를 구현합니다 WebException .

추가 정보

적용 대상

WebException(String, WebExceptionStatus)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지와 상태를 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

public:
 WebException(System::String ^ message, System::Net::WebExceptionStatus status);
public WebException (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)

매개 변수

message
String

오류 메시지 텍스트입니다.

status
WebExceptionStatus

WebExceptionStatus 값 중 하나입니다.

예제

다음 예제에서는 오류 메시지 및 를 지정하여 을 WebExceptionStatusthrow 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 ) 
{
   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

설명

WebException 인스턴스를 초기화할 합니다 Message 속성의 값으로 설정 message 하며 Status 속성의 값으로 설정 status합니다. 하는 경우 message 됩니다 nullMessage 속성은 시스템 제공 메시지로 초기화 합니다. 합니다 InnerException 하 고 Response 속성으로 초기화 됩니다 null합니다.

적용 대상

WebException(String, Exception)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지와 중첩된 예외를 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

message
String

오류 메시지 텍스트입니다.

innerinnerException
Exception

중첩된 예외입니다.

예제

다음 예제에서는 오류 메시지 및 중첩된 예외를 지정하여 을 throw 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( 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

설명

WebException 인스턴스를 초기화할 합니다 Message 속성의 값으로 설정 message 하며 InnerException 속성의 값으로 설정 innerException합니다. 하는 경우 message 됩니다 nullMessage 속성은 시스템 제공 메시지로 초기화 합니다. 합니다 InnerException 하 고 Response 속성으로 초기화 됩니다 null합니다. Status 속성이 RequestCanceled으로 초기화됩니다.

추가 정보

적용 대상

WebException(String, Exception, WebExceptionStatus, WebResponse)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지, 중첩된 예외, 상태 및 응답을 사용하여 WebException 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

message
String

오류 메시지 텍스트입니다.

innerinnerException
Exception

중첩된 예외입니다.

status
WebExceptionStatus

WebExceptionStatus 값 중 하나입니다.

response
WebResponse

원격 호스트에서 보낸 응답이 들어 있는 WebResponse 인스턴스입니다.

예제

다음 예제에서는 오류 메시지 및 를 지정하여 을 WebExceptionStatusthrow WebException 합니다.

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

설명

WebException instance 속성이 값으로 설정되고, InnerException 속성이 값messageinnerException으로 Message 설정되고, 속성이 Statusstatus으로 설정되고Response, 속성이 값response으로 설정되어 초기화됩니다. 하는 경우 message 됩니다 nullMessage 속성은 시스템 제공 메시지로 초기화 합니다.

적용 대상