后台的API中有 Ruqeust 参数名 和 Response状态码 还有什么返回Json对象 属性名 用socket能做到吗?
解决方案 »
- AVD 无法关闭
- Android 如何在treeview中加checkbox
- 请教:PopupWindow的一个问题
- mtk6513怎么进工程模式?
- mapview 继承了overlay ,重写draw方法时,通过draw方法画图,为什么draw方法调了十几次?
- intent 传递错误 但是没有报错信息 点击按钮退出
- java编译没错,但是打开程序报错
- 如何使 文本输入框根据【拼音首字母】自动补全
- 求助:用ant打包的时候,为什么没有把jni的.so文件打包进来啊
- 请教原安卓6代码适配到安卓9怎么快
- 哪个系统下使用用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,自己看下吧。