24 NİSAN 2011, Pazar
Nasıl Java'da bir string olarak http yanıtı bir vücut alabilirim?
Burada belirtildiği gibi apache commons onu almak için bir yol vardı biliyorum: http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HttpMethod.html ve burada bir örnek:
http://www.kodejava.org/examples/416.html
ama bu önerilmiyor inanıyorum. Bir java http get isteği yapmak ve bir dize olarak yanıt gövde elde etmek için başka bir yol ve bir dere değil mi?
CEVAP
6 Aralık 2012, PERŞEMBE
Burada benim üzerinde çalıştığım proje iki örnek.
-
HttpResponse response = httpClient.execute(new HttpGet(URL)); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); System.out.println(responseString);
BasicResponseHandler
kullanarakHttpResponse response = httpClient.execute(new HttpGet(URL)); String responseString = new BasicResponseHandler().handleResponse(response); System.out.println(responseString);
Bunu Paylaş: