求 有没有人有android通过servlet访问处理mysql获取json格式数据的简单范例或教程 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自己找到了public String post(String url, JSONObject json) { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 3000); HttpConnectionParams.setSoTimeout(httpParams, 3000); HttpClient client = new DefaultHttpClient(httpParams); HttpPost request = new HttpPost(url); try { request.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } request.setHeader("json", json.toString()); HttpResponse response; try { response = client.execute(request); if(response.getStatusLine().getStatusCode() == 200) { result= readstream(response.getEntity().getContent()); return result; }else { throw new Exception("can't connect the network"); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return "can't connect"; } 学习ViewPage实现无限左右滑动 请求解释一个异常 关于启用new Timer()的问题 如何杀掉本应用在堆栈中的所有activity,而不杀掉本应用的服务? 测试通讯录livefolder报错 如何做上面的列表 反编译了个android程序,象此类代码如何修改 ibeacon与蓝牙4.0是什么关系? 更改了编辑框中MyEditText中的输入法换行imeoptions后只对系统自带输入法有效,第三方输入法无效。怎么破 Android Studio 有没有懂二位条码的啊?帮我看看这个问题 Launch timeout has expired, giving up wake lock!
{
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
HttpConnectionParams.setSoTimeout(httpParams, 3000);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost request = new HttpPost(url);
try {
request.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setHeader("json", json.toString());
HttpResponse response;
try {
response = client.execute(request);
if(response.getStatusLine().getStatusCode() == 200)
{
result= readstream(response.getEntity().getContent());
return result;
}else {
throw new Exception("can't connect the network");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "can't connect";
}