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

  • Hudson Music

    Hudson Music

    13 Mart 2007
  • LiteralMSPaint

    LiteralMSPai

    27 EKİM 2010
  • Ralph Phillips

    Ralph Philli

    5 Aralık 2006

İLGİLİ SORU / CEVAPLAR