在安卓2.3.3 HTTP GET请求 [英] Http get request in Android 2.3.3
本文介绍了在安卓2.3.3 HTTP GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要发送 HTTP GET
请求帮助。我的code是如下:
I need help with sending HTTP GET
request. My code is as follows:
URL connectURL = new URL("url");
HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("GET");
conn.connect();
conn.getOutputStream().flush();
String response = getResponse(conn);
但它未能在 GETRESPONSE(康涅狄格州);
为什么
推荐答案
GET请求,可以使用这样的:
GET request could be used like this:
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://www.google.com";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
// do something with the response
String response = EntityUtils.toString(resEntityGet);
Log.i("GET RESPONSE", response);
}
} catch (Exception e) {
e.printStackTrace();
}
这篇关于在安卓2.3.3 HTTP GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文