SORU
8 HAZİRAN 2010, Salı


Java HTTP İstemci tanımlı zaman aşımı ile Talep

Benim bulut sunucu sayıda BİT (Dahili testleri) yapmak istiyorum. İstek büyük zaman aşımı başarısız olmaya ihtiyacım var.

Nasıl java ile bu yapmalıyım?

Böyle bir şey denemek aşağıda işe görünmüyor.

public class TestNodeAliveness {
 public static NodeStatus nodeBIT(String elasticIP) throws ClientProtocolException, IOException {
  HttpClient client = new DefaultHttpClient();
  client.getParams().setIntParameter("http.connection.timeout", 1);

  HttpUriRequest request = new HttpGet("http://192.168.20.43");
  HttpResponse response = client.execute(request);

  System.out.println(response.toString());
  return null;
 }


 public static void main(String[] args) throws ClientProtocolException, IOException {
  nodeBIT("");
 }
}

-- EDİT: kütüphane -- . kullanıldığını Açıklamak

Apache httpclient kullanıyorum, burada ilgili pom.xml bölümü

 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>4.0.1</version>
   <type>jar</type>
 </dependency>

CEVAP
9 HAZİRAN 2010, ÇARŞAMBA


import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

...

    // set the connection timeout value to 30 seconds (30000 milliseconds)
    final HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
    client = new DefaultHttpClient(httpParams);

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • chickenby

    chickenby

    2 HAZİRAN 2008
  • GoldgenieOfficial

    GoldgenieOff

    23 Temmuz 2009
  • max2sims2

    max2sims2

    19 Kasım 2008