解决方案 »
- 请问你们用哪家的包来实现定位啊
- 关于BitmapFactory.setDefaultConfig(Bitmap.Config.ARGB_8888);这个方法的使用
- launcher 改造
- 请问这种列表是如何做的.
- 关于类似桌面launcher滑动实现的问题~~在线求助
- android里调用c++程序生成.so后 调用失败
- 想玩玩android,请问需要什么环境。
- android使用代码控制无线热点
- Android开发中,怎么调用系统联系人界面,选择多个联系人并返回联系人数据?
- AccessibilityService的dispatchGesture总是返回false
- eclipse 导入带有C++的android项目。
- android EdiText文本滑动
HttpClient hc = new DefaultHttpClient();
try {
HttpResponse ht = hc.execute(httpGet);
if(ht.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
HttpEntity he = ht.getEntity();
InputStream is = he.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String response = "";
String readLine = null;
while((readLine =br.readLine()) != null){
//response = br.readLine();
response = response + readLine;
}
is.close();
br.close();
//String str = EntityUtils.toString(he);
System.out.println("========="+response);
return response;
}else{
return "error";
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "exception";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "exception";
}
另外何不考虑使用HttpUrlConnection?这个帖子对比了HttpUrlConnection和HttpClient,我觉得说的不错
http://http://blog.csdn.net/huzgd/article/details/8712187
HttpParams httpParams;
HttpClient httpClient;
HttpPost httpRequest = new HttpPost(url);
String response = "doPostError";
httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 4*1000);
HttpConnectionParams.setSoTimeout(httpParams, 6*1000);
HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
HttpClientParams.setRedirecting(httpParams, true);
String userAgent ="Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
HttpProtocolParams.setUserAgent(httpParams, userAgent);
httpClient = new DefaultHttpClient(httpParams);
try {
if (params != null) {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
}
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_0);
httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
HttpResponse httpResponse = httpClient.execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity=httpResponse.getEntity();
InputStream is = httpEntity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String readLine = null;
while((readLine =br.readLine()) != null){
//response = br.readLine();
response = response + readLine;
}
is.close();
br.close();
} else {
response = "Error Response: " + httpResponse.getStatusLine().toString();//获取响应码
}
} catch (ClientProtocolException e) {
// strResult = e.getMessage().toString();
e.printStackTrace();
} catch (IOException e) {
// strResult = e.getMessage().toString();
e.printStackTrace();
}catch (Exception e) {
// strResult = e.getMessage().toString();
e.printStackTrace();
} System.out.println("strResult =" + response); return response;
}
httpPost.setEntity(httpEntity);
HttpResponse httpResponse = httpClient.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = httpResponse.getEntity();
return EntityUtils.toString(entity, "utf-8");
用这个,直接转成String试试。