Windows Phone では、if で取得WebException
できStatusCode == HttpStatusCode.NotFound
ます
- サーバーが 404 を返しました
- 接続が悪いため、サーバーが見つかりません。
On Windows PhoneWebException
のステータスはWebExceptionStatus.UnknownError
両方の場合です。
1
case とcaseを区別するにはどうすればよい2
ですか?
私が観察したのは、接続が悪い (サーバーが見つからない)ResponseUri
が null で、WebResponse
ヘッダーに0
アイテムが含まれている場合です。
EDIT
ResponseUri
は null ではなく、OriginalString
空です
これを行うのは安全ですか:
catch (WebException ex)
{
switch (ex.Response.StatusCode)
{
...
case HttpStatusCode.NotFound:
if (ex.Response.ResponseUri == null
|| string.IsNullOrEmpty(httpWebResponse.ResponseUri.OriginalString))
DoServerNotFound();
else
DoServerReturned404();