android开发 与后台数据交互 后台的API中有 Ruqeust 参数名 和 Response状态码 还有什么返回Json对象 属性名 用socket能做到吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 发给我一份例子吧[email protected] 谢谢了 我也要一个例子 [email protected] 速求啊~!!!! /** * connection 连接 * @throws IOException */ private void initConn() throws IOException { // Http 连接Url URL url = new URL("http://218.2..............."); // 使用HttpURLConnection打开连接 urlConn = (HttpURLConnection) url.openConnection(); // 设置为POST请求 urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setRequestMethod("POST"); } /** * 字符串通过流来发送接收 * @throws IOException */ private void doTask() throws IOException { try { initConn(); Log.i(myUrl+"-1", "发送请求成功!"); } catch (IOException e) { Log.i(myUrl+"-2", "请求超时!"); e.printStackTrace(); return; } // 为发送创建BufferedWriter BufferedWriter outbuffer = new BufferedWriter(new OutputStreamWriter(urlConn.getOutputStream())); Log.i(myUrl+"-3", outputLine.toString()); // 写入字符串 outbuffer.write("data="+outputLine); // 关闭buffer outbuffer.close(); // 获取连接返回值 int resCode = urlConn.getResponseCode(); if (resCode == 200) { // 输入字节流 ins = urlConn.getInputStream(); /** * 文件按流读 */ out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = ins.read(b)) != -1;) { out.append(new String(b, 0, n)); } if (ins != null) { ins.close(); } // 使用循环来读取获得的数据 String res = JsonUtil.jsonDecode(out.toString().trim()); Log.i(myUrl+"-4", "Request值:"+res); // 关闭http连接 urlConn.disconnect(); // 回调函数UI显示 impl.recount(res); } }楼主估计没写过JAVA web,这有个Demo,自己看下吧。 Android牟利之道(一)--界面嵌入有米广告 【高分】求大神解决难题 bootanimation 不流畅问题 项目中频繁通话报出空异常!求思路解决! TabHost问题 如何获取系统是什么型号 奔溃,ImageView及分辨率问题! 菜鸟求助,eclipse无法创建AVD layout_alignParentLeft 没有这个? PhoneGap出毛病了 哪个系统下使用用eclipse开发android好点? 哪位大侠会做android的UI,通过PS然后切图。新手请教。谢谢。
* connection 连接
* @throws IOException
*/
private void initConn() throws IOException {
// Http 连接Url
URL url = new URL("http://218.2...............");
// 使用HttpURLConnection打开连接
urlConn = (HttpURLConnection) url.openConnection();
// 设置为POST请求
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setRequestMethod("POST");
}
/**
* 字符串通过流来发送接收
* @throws IOException
*/
private void doTask() throws IOException {
try {
initConn();
Log.i(myUrl+"-1", "发送请求成功!");
} catch (IOException e) {
Log.i(myUrl+"-2", "请求超时!");
e.printStackTrace();
return;
}
// 为发送创建BufferedWriter
BufferedWriter outbuffer = new BufferedWriter(new OutputStreamWriter(urlConn.getOutputStream()));
Log.i(myUrl+"-3", outputLine.toString());
// 写入字符串
outbuffer.write("data="+outputLine);
// 关闭buffer
outbuffer.close();
// 获取连接返回值
int resCode = urlConn.getResponseCode();
if (resCode == 200) {
// 输入字节流
ins = urlConn.getInputStream();
/**
* 文件按流读
*/
out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = ins.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
if (ins != null) {
ins.close();
}
// 使用循环来读取获得的数据
String res = JsonUtil.jsonDecode(out.toString().trim());
Log.i(myUrl+"-4", "Request值:"+res);
// 关闭http连接
urlConn.disconnect();
// 回调函数UI显示
impl.recount(res);
}
}楼主估计没写过JAVA web,这有个Demo,自己看下吧。