WebException.Status プロパティ
アセンブリ: System (system.dll 内)

WebExceptionStatus 値の 1 つ。


Status プロパティをチェックし、元になる HttpWebResponse インスタンスの StatusCode および StatusDescription をコンソールに出力する例を次に示します。
Try 'Create a web request for an invalid site. Substitute the "invalid site" strong in the Create call with a invalid name. Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("invalid site"), HttpWebRequest) 'Get the associated response for the above request. Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse) myHttpWebResponse.Close() Catch e As WebException Console.WriteLine(e.Message) If e.Status = WebExceptionStatus.ProtocolError Then Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode) Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription) End If Catch e As Exception Console.WriteLine(e.Message) End Try
try { // Create a web request for an invalid site. Substitute the "invalid site" strong in the Create call with a invalid name. HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("invalid site"); // Get the associated response for the above request. HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse(); myHttpWebResponse.Close(); } catch(WebException e) { Console.WriteLine("This program is expected to throw WebException on successful run."+ "\n\nException Message :" + e.Message); if(e.Status == WebExceptionStatus.ProtocolError) { Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode); Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription); } } catch(Exception e) { Console.WriteLine(e.Message); }
try { // Create a web request for an unknown server (this raises the WebException). HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)(WebRequest::Create( "http://unknown.unknown.com" )); // Get the associated response for the above request. HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)(myHttpWebRequest->GetResponse()); myHttpWebResponse->Close(); } catch ( WebException^ e ) { Console::WriteLine( "This program is expected to throw WebException on successful run." + "\n\nException Message : " + e->Message ); if ( e->Status == WebExceptionStatus::ProtocolError ) { Console::WriteLine( "Status Code: {0}", ( (HttpWebResponse^)(e->Response) )->StatusCode ); Console::WriteLine( "Status Description: {0}", ( (HttpWebResponse^)(e->Response) )->StatusDescription ); } } catch ( Exception^ e ) { Console::WriteLine( e->Message ); }
try { // Create a web request for an invalid site. Substitute the // "invalid site" strong in the Create call with a invalid name. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest. Create("invalid site"); // Get the associated response for the above request. HttpWebResponse myHttpWebResponse = ( HttpWebResponse)myHttpWebRequest.GetResponse(); myHttpWebResponse.Close(); } catch (WebException e) { Console.WriteLine("This program is expected to throw WebException" + " on successful run." + "\n\nException Message :" + e.get_Message()); if (e.get_Status().Equals(WebExceptionStatus.ProtocolError)) { Console.WriteLine("Status Code : {0}", ((HttpWebResponse)(e. get_Response())).get_StatusCode()); Console.WriteLine("Status Description : {0}",((HttpWebResponse)( e.get_Response())).get_StatusDescription()); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebExceptionStatus 列挙体
アセンブリ: System (system.dll 内)

Public Enumeration WebExceptionStatus

メンバ名 | 説明 | |
---|---|---|
CacheEntryNotFound | 指定したキャッシュ エントリが見つかりませんでした。 | |
![]() | ConnectFailure | トランスポート レベルで、リモート サービス ポイントと通信できませんでした。 |
![]() | ConnectionClosed | 接続を終了するのが早すぎました。 |
![]() | KeepAliveFailure | Keep-alive ヘッダーを指定する要求のための接続が予期せずに閉じられました。 |
MessageLengthLimitExceeded | サーバーに要求を送信、またはサーバーからの応答を受信しているときに、制限長を超えるメッセージが渡されました。 | |
![]() | NameResolutionFailure | 名前解決サービスがホスト名を解決できませんでした。 |
![]() | Pending | 内部非同期要求が保留中です。 |
![]() | PipelineFailure | 要求がパイプライン処理された要求で、応答の受信前に接続が閉じられました。 |
![]() | ProtocolError | サーバーから受信した応答は完了しましたが、プロトコルレベルのエラーを示しています。たとえば、"401 アクセス拒否" などの HTTP プロトコル エラーは、このステータスを使用します。 |
![]() | ProxyNameResolutionFailure | 名前解決サービスがプロキシ ホスト名を解決できませんでした。 |
![]() | ReceiveFailure | リモート サーバーから完全な応答が受信されませんでした。 |
![]() | RequestCanceled | 要求がキャンセルされたか、WebRequest.Abort メソッドが呼び出されたか、または分類できないエラーが発生しました。これは Status の既定値です。 |
RequestProhibitedByCachePolicy | 要求はキャッシュ ポリシーで許可されませんでした。これは通常、要求をキャッシュに保存できず、有効なポリシーによってサーバーへの要求の送信が禁止されている場合に発生します。このステータスは、要求メソッドが要求本体の存在を示している場合、要求メソッドがサーバーとの直接の対話を要求している場合、または要求に条件ヘッダーが含まれている場合に受け取ることがあります。 | |
RequestProhibitedByProxy | この要求はプロキシで許可されませんでした。 | |
![]() | SecureChannelFailure | SSL を使用して接続を確立する際にエラーが発生しました。 |
![]() | SendFailure | 完全な要求をリモート サーバーに送信できませんでした。 |
![]() | ServerProtocolViolation | サーバー応答が有効な HTTP 応答ではありません。 |
![]() | Success | エラーは発生しませんでした。 |
![]() | Timeout | 要求のタイムアウト時間中に応答が受信されませんでした。 |
![]() | TrustFailure | サーバー証明書を検証できませんでした。 |
UnknownError | 未知の種類の例外が発生しました。 |


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- WebException.Statusのページへのリンク