使用http协议,服务器采用tomcat servlet
解决方案 »
- IDA+GDB调试安卓c代码[原创]
- 哪里有完整的闹钟源代码下??
- abdroid线程弹出对话框失败
- android 为什么我的OnClickListener 继承的 方法是public void onClick(DialogInterface dialog,
- SurfaceHolder.lockCanvas() = null的问题
- Android C++开发的问题?
- android如何实现分散对齐
- 点击按钮toast为什么没有显示啊?求解!
- android独立应用之间的调用返回问题
- ListView的item里设置的RatingBar,为什么不能动态改变颜色?
- 怎么等待一个线程结束?希望等待的过程中界面不能卡死..
- android如何将一个网页上的表格显示在手机上
* 根据url获得页面源码
* @param url 访问地址, 必备参数
* @param method 请求方式post还是get, 默认get
* @param params 参数列表 post必备, 比如:"name=张三&age=18"
* @param sessionInfo 可以保持session, 默认不保持
* @param encoding 编码格式, 默认UTF_8
* @param isLine 得到的源码是否换行, 默认false
* @return
*/
public String sound(String url, String method, String params, String sessionInfo, String encoding, boolean isLine) throws Exception {
encoding = (isBlank(encoding) ? HTTP.UTF_8 : encoding);
method = (isBlank(method) ? Domain.REQUEST_GET : method.toUpperCase());
String mathStr = "mathRandom=" + Math.random();
if (method.equals(Domain.REQUEST_GET)) {url += (url.indexOf("?") != -1 ? "&" : "?") + mathStr;}
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
if (!isBlank(sessionInfo)) {conn.setRequestProperty("Cookie", sessionInfo);}
conn.setRequestMethod(method);
if (requestTime > 0) {
conn.setConnectTimeout(requestTime);
conn.setReadTimeout(requestTime);
}
if (method.equals(Domain.REQUEST_POST)) {
conn.setDoOutput(true);
OutputStream output = conn.getOutputStream();
output.write((isBlank(params) ? mathStr : params + "&" + mathStr).getBytes(encoding));
output.flush();output.close();
}
String response = FileUtil.get().readFile(conn.getInputStream(), encoding, 1, isLine);
conn.disconnect();
requestTime = Domain.LONG_REQUEST_TIME;
return response;
}
用java感觉太过繁琐。