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

  • Doc Adams

    Doc Adams

    20 HAZİRAN 2007
  • dope2111

    dope2111

    29 HAZİRAN 2009
  • Tylerron

    Tylerron

    6 AĞUSTOS 2006

İLGİLİ SORU / CEVAPLAR