SORU
24 HAZİRAN 2011, Cuma


Nasıl HTTP yanıt kodu almak için Java'da bir URL için?

Benim adım particlular bir URL yanıt kodu almak için kod söyle lütfen.

CEVAP
24 HAZİRAN 2011, Cuma


HttpURLConnection:

URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();

int code = connection.getResponseCode();

Bu hiçbir şekilde sağlam bir örnektir; IOExceptions kolu ve etajer gerekir. Ama başlamak gerekir.

Eğer daha fazla kapasiteli bir şeye ihtiyacın olursa, HttpClient check out.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • HouseholdHacker

    HouseholdHac

    6 Kasım 2007
  • Attempts at least

    Attempts at

    1 Ocak 2007
  • Marina and The Diamonds

    Marina and T

    8 Temmuz 2008

İLGİLİ SORU / CEVAPLAR