SORU
26 AĞUSTOS 2010, PERŞEMBE


Nasıl Professional (Service durum kodu almak için?

WebClient sınıfı bir web formu için bazı veri göndermek için kullanıyorum. Form gönderme yanıt durum kodu almak istiyorum. Şimdiye kadar eğer bir istisna varsa, durum kodu almak için nasıl öğrendim

Catch wex As WebException
        If TypeOf wex.Response Is HttpWebResponse Then
          msgbox(DirectCast(wex.Response, HttpWebResponse).StatusCode)
            End If

Ancak form başarıyla gönderildi ve hiçbir özel durum, durum kodu(200,301,302,...) bilemem

Bazı özel durumlar için durum olduğunda durum kodu almak yok?

PS: httpwebrequest/httpwebresponse kullanmamayı tercih ederim

CEVAP
9 ŞUBAT 2012, PERŞEMBE


Eğer hata 5 ** türü olup olmadığını kontrol edebilirsiniz ve daha sonra yanıt kodu kontrol;

if (e.Error.GetType().Name == "WebException")
{
   WebException we = (WebException)e.Error;
   HttpWebResponse response = (System.Net.HttpWebResponse)we.Response;
   if (response.StatusCode==HttpStatusCode.NotFound)
      System.Diagnostics.Debug.WriteLine("Not found!");
}

ya

try
{
    // send request
}
catch (WebException e)
{
    // check e.Status as above etc..
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • androidandme

    androidandme

    10 Mart 2009
  • Artorius FullPower

    Artorius Ful

    29 Temmuz 2007
  • finalcall07

    finalcall07

    11 NİSAN 2008